Hot Deployment with Jetty Plugin for Gradle - gradle

I am currently using the Jetty plugin for gradle for development:
apply plugin: 'war'
apply plugin: 'jetty'
...
jettyRunWar {
httpPort = 8080
reload = 'automatic'
scanIntervalSeconds = 2
daemon = false
}
jettyRun {
httpPort = 8080
reload = 'automatic'
scanIntervalSeconds = 2
daemon = false
}
However, the hot deployment is not working as expected. When using gradle jettyRunWar, the plugin seems to reload the context when using gradle war, but nothing changes really. When using gradle jettyRun, the reloading works, but JSF is no longer working:
Could not instantiate listener com.sun.faces.config.ConfigureListener: java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
AnnotationConfigurator does not found classes for annotations in /WEB-INF/classes/ . This could happen because maven jetty plugin is used (goal jetty:run). Try configure org.apache
.myfaces.annotation.SCAN_PACKAGES init parameter or use jetty:run-exploded instead.
Any ideas how to get one of these options to work? Setting the mentioned parameter leads just to more exceptions.

Related

gradle init script can't apply artifactory plugin

I'm trying to offload build logic into a gradle init script, which gets included in a custom gradle wrapper. It seems promising. One of the things I need to do is to apply the artifactory plugin prior to configuring it, while the following code works fine in build.gradle, it fails to find the plugin when the code is shifted into an init script.
build.gradle:
buildscript{
Properties properties = new Properties()
properties.load(new File(gradle.getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())
repositories {
maven {
url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
credentials {
username = properties.artifactory_user
password = properties.artifactory_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
}
}
apply plugin: "com.jfrog.artifactory"
and in the init script it's almost the same:
initscript{
Properties properties = new Properties()
properties.load(new File(getGradleUserHomeDir(), 'gradle.properties').newDataInputStream())
repositories {
maven {
url properties.artifactory_contextUrl + '/gradle-plugins-virtual'
credentials {
username = properties.artifactory_user
password = properties.artifactory_password
}
}
}
dependencies {
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2"
}
}
apply plugin: "com.jfrog.artifactory"
but I get Plugin with id 'com.jfrog.artifactory' not found. with this attempt.
I have also tried making an init plugin, but my plugin skills are not strong, and it also seems to fail.
I tried moving just the apply plugin line to build.gradle from the init script but that also fails, indicating it might be the dependency resolution. How can I debug this further?
I did a build scan and it appears that the plugin jar was found okay.
org.jfrog.buildinfo:build-info-extractor-gradle:4.17.2
commons-io:commons-io:2.7
commons-lang:commons-lang:2.4
commons-logging:commons-logging:1.1.1
1.2
org.apache.ivy:ivy:2.2.0
org.jfrog.buildinfo:build-info-extractor:2.19.2
Any help, comments, suggestions appreciated.
Rant: gradle docs have far too few examples.
For gradle init script, you must use the fully qualified class name of the plugin instead of the id.
Like this:
apply plugin: org.jfrog.gradle.plugin.artifactory.ArtifactoryPlugin

Using Gradle property expansion in kotlin/spring boot

I am currently building a Kotlin, Spring Boot service using gradle as the build tool. I am attempting to automatically expand properties found in my application.properties file, using the steps found here:
https://docs.spring.io/spring-boot/docs/current/reference/html/howto-properties-and-configuration.html#howto-automatic-expansion-gradle
My versions are as follows:
- kotlin: 1.1.4-3
- spring boot: 1.5.6.RELEASE
- gradle: 3.5.1
When I run a ./gradlew bootRun, I get the following error:
java.lang.IllegalArgumentException: Could not resolve placeholder 'myServiceName' in value "${myServiceName}"
Followed by:
java.lang.IllegalStateException: LifecycleProcessor not initialized - call 'refresh' before invoking lifecycle methods via the context: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#510aeb93: startup date [Fri Sep 15 10:59:51 AEST 2017]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#68edf5bb
build.gradle:
apply plugin: 'kotlin'
apply plugin: 'kotlin-spring'
apply plugin: 'org.springframework.boot'
processResources {
filesMatching('application.properties') {
expand(project.properties)
}
}
gradle.properties:
myServiceName=potato-service
application.properties:
info.app.name=${myServiceName}
These errors appear after the app has started, and spring is trying to load the property file.
The interesting thing is that if I change the variable that I am trying to substitute in the application.properties, to myServiceName123 for example, gradle fails at the processResources stage.
So, there was a small part of my build.gradle that I did not include above as I did not know about it:
bootRun {
addResources = true
}
According to the Spring Boot Docs having the addResources flag set to true will ignore the application.properties file created in the processResources step, and instead use the one in your projects sources. This is to allow you to dynamically change the file without needing to restart the application.
The correct fix for this (if you need variable expansion when running with the bootRun task) is to set:
bootRun {
addResources = false
}
Otherwise, if you just need expansion when building your jar, leaving this flag as true should be fine.

Connect SonarQube (4.5.4 ) with Gradle (2.1) throws HTTP 400

I want to connect Gradle (Version 2.1) with SonarQube (4.5.4 LTS), but there is this Exception
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':<myProject>:sonarAnalyze'.
> java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:9000/batch/
* Try:
Run with --debug option to get more log output.
Relating to this Post it shoud be possible, and here is maybe the Bug with the related workaround.
But how can I use it? Unpacking the zip into the Project and importing the lines from the build.gradle from the zip-file doesn't work for me :( (makes no difference).
The sonar-configuration in build.gradle:
apply plugin: "sonar"
sonar {
server {
url = "http://localhost:9000"
}
database {
url = "jdbc:mysql://localhost:3306/sonar"
driverClassName = "com.mysql.jdbc.Driver"
username = "sonar"
password = <myPassword>
}
}
apply plugin: 'sonar-runner'
sonarRunner {
sonarProperties {
property 'sonar.host.url', 'http://localhost:9000'
}
}
Thanks in advance :)
PS: Gradle and Sonarqube are working fine.
Sonar Plugin is deprecated:
You may wish to use the new Sonar Runner Plugin instead of this
plugin. In particular, only the Sonar Runner plugin supports Sonar 3.4
and higher.
Use the Sonar Runner Plugin only
apply plugin: "sonar-runner"
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000"
property "sonar.jdbc.url", "jdbc:mysql://localhost:3306/sonar"
property "sonar.jdbc.driverClassName", "com.mysql.jdbc.Driver"
property "sonar.jdbc.username", "sonar"
property "sonar.jdbc.password", "<myPassword>"
}
}
In fact the two SonarQube plugins part of the Gradle distribution are now deprecated. See the following official message from the Gradle team: https://twitter.com/gradle/status/613530568655966208. Only the new one directly maintained by the SonarSource team should be used : http://docs.sonarqube.org/display/SONAR/Analyzing+with+Gradle

Gradle jetty plugins how to run it on a specific ip address and port number

I have a web service which is executable with gradle jettyRun task. If I run it runs on localhost:8080. I want to run it on a specific ip address and port number. My current build.gradle is as follows:
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'war'
apply plugin: 'jetty'
jettyRun {
reload = "automatic"
scanIntervalSeconds = 10
}
Other dependencies are removed. I know about the docs I just don't know the syntax. How to configure host and port?
What You need is:
//other plugins
apply plugin: 'jetty'
httpPort = 9000
jettyRun {
reload = "automatic"
scanIntervalSeconds = 10
}
As far as I know host isn't configurable - You just run it and it depends on os specific configuration if it's accessible from other hosts or not.
Adding to #Opal answer, you can also run Jetty at a specific port by using below configuration in build.gradle:
jettyRun {
reload = "automatic"
scanIntervalSeconds = 10
httpPort = 9999
}
or shorthand version jettyRun.httpPort = 9999
And for jettyRunWar task with following configuration:
jettyRunWar {
reload = "automatic"
scanIntervalSeconds = 10
httpPort = 9999
}
or jettyRunWar.httpPort=9999

Proper way to install/run a gradle plugin from github (specifically the arquilian plugin)?

I would like to use the arquillian plugin here to run jetty 8+:
https://github.com/aslakknutsen/arquillian-gradle-plugin
If I put "apply plugin: 'arquillian'" in my gradle script, it does not find it.
So I must have to install it somehow. I look for info on this, but did not find.
Would you have a pointer on how to do that?
I am using gradle 1.6 on windows.
Update after answer by #raeffs:
I updated the gradle script with it and the build is successfull, but I don't see my war started after an arquillianRunJetty (port 8080 is not even listening).
Then I tried to add what is indicated on the github page:
arquillian {
debug = true
deployable = file('my/path/arbitraryWebApp.war')
containers {
jetty {
version = '8'
type = 'embedded'
config = ['bindHttpPort': 8080, 'bindAddress': '127.0.0.1', 'jettyPlus': false]
dependencies {
adapter 'org.jboss.arquillian.container:arquillian-jetty-embedded-7:1.0.0.CR2'
container 'org.eclipse.jetty:jetty-webapp:8.1.11.v20130520'
container group: 'org.eclipse.jetty', name: 'jetty-plus', version: '8.1.11.v20130520'
}
}
I had to replace arquillian-jetty-embedded-7:1.0.0.CR2 with CR1 as it is not in maven central.
Then I put the path to my war. When starting again, there is more chatter but still no listening on port 8080.
So I still miss something.
I also find awkward to have to reference with an absolute path for the war I am building with the gradle script. I think there could be a kind of self reference.
Update
It is running fine now thanks to #raeffs. I don't really know what was wrong in my previous step.
The path to the web app takes the name, plus the version.
Thank you
The creator of the plugin has not published it to a maven repository, so you have to build it on your own.
Get a local copy of the plugin project and build it. You should get a the 'arquillian-gradle-plugin-0.1.jar' as output.
In the build script of yout own project you have to declare a dependency to that jar. Add the following to your build script:
buildscript {
dependencies {
classpath fileTree(dir: '/path/to/folder/that/contains/the/jar',
includes: ['arquillian-gradle-plugin-0.1.jar'])
}
}
Now you should be able to use the plugin.
Update
If you do not want to provide a hardcoded path to your deployable you could simply pass a variable. For example if you are using the war plugin:
arquillian {
deployable = war.archivePath
}
Here is an example of the usage: https://gist.github.com/raeffs/5920562#file-build-gradle
It starts the jetty container, deploys the war and waits until ctrl+c is pressed.

Resources