Gradle v1.4
I have multi module project, with many java modules and one non-java module. Therefore, I’ve create the following:
def javaModules() {
tasks.matching { it.name.contains(‘jodd-’) }
}
configure(javaModules()) {
apply plugin: ‘java’
…
but this does not work: “Could not find property ‘build’ on task set.” (because root project does not have build task?)
I also tried:
subprojects.findAll {it.name.contains(‘jodd-’)}
for definition of ‘javaModules’, but this failed again: “Could not find property ‘sourceSets’ on project ‘:distribution’.” (‘distribution’ is the non-java project, and i am using ‘sourceSets’ in above configure)
I am obviously missing something here. What is the proposed way to split submodules into groups that I can configure independently and that i can use for dependsOn?
Ok, i figured. the second way is just fine; but then you need to use ‘javaModules()’ on all your aggregation tasks, and not simple ‘submodules’
btw, you should really print out line number of the error in console
i figured out what is going on when only when i started --gui, as it displays the error line number
There is an alternative pattern to potentially accomplish what you want:
allprojects {
plugins.withType(JavaPlugin).whenPluginAdded {
// do Java specific configurations
}
}
This assumes you are manually applying the java plugin in each subproject build.gradle, which is often still useful to have to configure subproject specific behavior locally.
But, if you wanted to do it all from the root project, then you can utilize the subprojects.findAll(Closure) mechanism you’ve mentioned to at least selectively choose projects for configuration purposes, which could be as simply as apply plugin: ‘java’ for project names containing ‘jodd-’ like you have above.
The advantage to watching for the plugin application, is that you catch all projects without any special pattern matching. The disadvantage is that you catch them all, so you need to ensure that you are applying settings that are truly universal to java projects, and not just those java projects with the name ‘jodd-’ in them.
-Spencer