Below you will find pages that utilize the taxonomy term “Gradle”
Building custom libs that are missing in maven central or jcenter
So you really need that java lib somebody made but they can’t be bothered to upload it to maven central or jcenter? Build it yourself and host it on your nexus repo. That’s what the script below does. Additionally, it includes a little xslt magic which allows to change the pom.xml in any way you want. Are they using snapshot versions? No problem, just insert your own (as shown in the script). Need to change a dependency? With some more xslt you can definitely do that too! You can run this script locally or on a build server (the script is using jenkins’ BUILD_NUMBER environment variable).
Reuse repository definitions in gradle
A project I’m working on has accumulated a bunch of repositories we need for the build.gradle script and for the build itself. I don’t want to keep everything twice so I thought some re-use is in order. Thanks to the excellent gradle javadocs and api design, it was easy to accomplish. The end result is this:
// add your repositories here
buildscript {
repositories {
mavenLocal()
jcenter()
maven {
credentials {
username 'user'
password 'pass'
}
url 'https://example.com/maven2'
}
}
// re-use repositories from buildscript
buildscript.repositories.each { repositories.add(it) }
To gradle daemon or not to gradle daemon?
The gradle daemon speeds up builds quite a bit and you do want to have it running on your local machine but not on the build server, that one should always re-build from scratch. This is actually quite easy to accomplish.
In your ‘~/.bashrc’ add the following export so your local machine runs all builds with the gradle daemon:
export GRADLE\_OPTS="-Dorg.gradle.daemon=true"
Since, by default, the gradle daemon is not started, it will not be used on your build server.
Using WSDLToJava with Gradle
I currently need to generate some java sources from a wsdl with Gradle. In Maven, I’ve done this using the cxf-codegen-plugin but I want to avoid using anything that’s maven in my new build. And there’s several resources out there who will either tell you to call WSDLToJava via cxf’s ant task or directly. The ‘direct’ way still leaves you with several possibilities like calling ProcessBuilder from your Gradle Task or using a JavaExec Task. I went for the last.
Using WSDLToJava with Gradle
I currently need to generate some java sources from a wsdl with Gradle. In Maven, I’ve done this using the cxf-codegen-plugin but I want to avoid using anything that’s maven in my new build. And there’s several resources out there who will either tell you to call WSDLToJava via cxf’s ant task or directly. The ‘direct’ way still leaves you with several possibilities like calling ProcessBuilder from your Gradle Task or using a JavaExec Task. I went for the last.
Anatomy of a Gradle Task: Task Dependencies
Here’s another little “gotcha” on gradle tasks. When they’re triggered. I’ve seen quite a few posts on stackoverflow along the lines of “How can I call a gradle task”. You can’t (Well ok you could but you don’t want to). It is executed as a dependency of another task.
Going back to that little copy task I wanted to execute, I needed it to run roughly somewhere after the clean task and before jar task. I ended up making my copy task dependent of compile. That didn’t work so I tried compileJava and classes and… only to later realize that the dependency was in the wrong direction: My task depends on one that is being executed but that doesn’t trigger my task, it merely states that my task, should it be executed, can only be run after some other task.
Anatomy of a Gradle Task: Task Dependencies
Here’s another little “gotcha” on gradle tasks. When they’re triggered. I’ve seen quite a few posts on stackoverflow along the lines of “How can I call a gradle task”. You can’t (Well ok you could but you don’t want to). It is executed as a dependency of another task.
Going back to that little copy task I wanted to execute, I needed it to run roughly somewhere after the clean task and before jar task. I ended up making my copy task dependent of compile. That didn’t work so I tried compileJava and classes and… only to later realize that the dependency was in the wrong direction: My task depends on one that is being executed but that doesn’t trigger my task, it merely states that my task, should it be executed, can only be run after some other task.
Anatomy of a Gradle Task: Execution Time
So I’m trying out gradle in the hope of being able to simplify and streamline an existing maven build which is quite large and inconsistent. And I just spent some time to figure out a few gotcha about gradle tasks and this post is to help others understand, because I think the gradle docs aren’t clear enough on this point
What I wanted to achieve is, to copy all *.properties files in src/main/java to the resources-output directory so they are included in the jar, because javac won’t pick them up since they’re no java source files. What happened was that, depending on what approach I tried, sometimes the copy worked sometimes it didn’t and I couldn’t understand why.
Anatomy of a Gradle Task: Execution Time
So I’m trying out gradle in the hope of being able to simplify and streamline an existing maven build which is quite large and inconsistent. And I just spent some time to figure out a few gotcha about gradle tasks and this post is to help others understand, because I think the gradle docs aren’t clear enough on this point
What I wanted to achieve is, to copy all *.properties files in src/main/java to the resources-output directory so they are included in the jar, because javac won’t pick them up since they’re no java source files. What happened was that, depending on what approach I tried, sometimes the copy worked sometimes it didn’t and I couldn’t understand why.