I have created a custom wsimport task that successfully manages to control the up-to-date nature of the WSDL and schemas, but it feels like I am cheating to properly integrate the generated output of wsimport.
By default, I am outputting the class files to ‘project.sourceSets.main.output.classesDir’, which works appropriately enough, but I am not a fan of reusing the ‘main’ source set for generated code output.
As such, I created a ‘generated’ source set:
sourceSets {
generated {
// is this too specific?
java.srcDirs = ["$buildDir/generated/java"]
}
}
However, from there I am at a loss in the best practice to join the ‘generated’ source set back with the main code. Currently, I use the ‘compileGeneratedJava’ task, but it feels wrong, as I use it to manually add the source files (not classes even) to the main java source set, which seems like it is brittle if some other task decides to do something similar:
compileGeneratedJava {
dependsOn(processWsdl)
// currently unnecessary
// options.warnings = false
// dump generated code into the global codebase
compileJava.source files(processWsdl.srcDir), sourceSets.main.java
}
However, in doing that, it will no longer consider the WSDL up to date, even when it is, thereby kicking off ‘processWsdl’ for every build.
What’s the best way to get the generated output into a separate folder, but still keep it a part of the build? The optimal feeling answer would be:
build/generated/java // or any variation of the name, such as build/generated/src/main/java
build/generated/classes
build/classes
And then, something knows to merge the two classes dirs (generated first) without the task even having to be made aware that it’s not part of the main code–it just spits generated output into a directory that you tell it too. It would be magical if IDEs could also pickup the structure and work with it.