I try to use Gradle on an ant-based Java project. We produce a war file and four jar files. These jar files use some of the classes that also go in the war file, e.g., the reset password utility jar uses some of the database access classes and the user classes.
I can build the war file just fine. How do I specify that I also want to build these jar files?
I looked into multi-project builds but I cannot put these jar files in separate source directories cause they need classes from the war’s sources. Also, during transition from ant to gradle I’d like to keep the directory structure as is.
Hi Robert, I think in your scenario you should split up your sources by defining different sourceSets. SourceSets can be depend on each other and declaring a jar out of the sourceSet is quite simple. Have a look in the userguide at http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:source_sets to find more details about that.
This gets me a warning about defining dynamic properties. I’ve tried sources, source, and others, but no luck. http://www.gradle.org/docs/current/userguide/java_plugin.html does only mention ‘srcDirs’ which don’t really work for me cause I only want to include certain files.
Hence I added this:
compileMyJarJava {
dependsOn "someGeneratedCode"
source = files("src/com/...", "src/com/...") // same list as above
}
Is it better to define the source files in the sourceSets and if so, how do I do that? Is this very un-gradle-ish and how could I improve it? Any other comments?
You get a warning because there is no ‘srcFiles’ property. Instead you’d use ‘srcDirs’ together with ‘include’ and/or ‘exclude’. See the Gradle Build Language Reference for an example.
It’s a little weird that it insists on the backslash after the include if I don’t want to place the included file on the same line but I can live with that.
Specifying includes/excludes per source directory isn’t currently supported. At best, your syntax will (accidentally) have the same effect as the official syntax shown above.