Using the following sample build.gradle script that worked in gradle 1.4, but fails in 1.5:
apply plugin: 'java'
task compileJava(type: MyCompileJavaTask, overwrite: true) {
sourceSet sourceSets.main
configuration configurations.compile
println "### USING MyCompileJavaTask instead of default compileJava"
}
class MyCompileJavaTask extends DefaultTask {
def sourceSet
@Input
def configuration
public void setConfiguration(configuration) {
this.configuration = configuration
dependsOn configuration.getTaskDependencyFromProjectDependency(true, "jar")
}
@InputFiles
public FileCollection getClasspath() {
sourceSet.compileClasspath
}
@InputFiles
public FileCollection getSources() {
sourceSet.java
}
@OutputDirectory
public File getDestinationDir() {
sourceSet.output.classesDir
}
@TaskAction
def compile() {
println "### TODO Executing my own Java compilation task"
}
}
task printCompileJavaType << {
println("### compileJava type now: ${compileJava.getClass().toString()}")
}
compileJava.dependsOn printCompileJavaType
If you run task
compileJava
, then the output is
### USING MyCompileJavaTask instead of default compileJava
:task-overwrite:printCompileJavaType
### compileJava type now: class MyCompileJavaTask_Decorated
:task-overwrite:compileJava
### TODO Executing my own Java compilation task
BUILD SUCCESSFUL
as expected. If you run task
classes
(or any other task that depends on the replaced
compileJava
task directly or indirectly), then the output is
### USING MyCompileJavaTask instead of default compileJava
:task-overwrite:compileJava
:task-overwrite:processResources UP-TO-DATE
:task-overwrite:classes
BUILD SUCCESSFUL
which is incorrect. The dependant tasks originally created by the java plugin still use the original
compileJava
task.
Are there any ways of working around this, other than manually setting the dependencies of all the directly dependant tasks (horrible solution)? Any help is greatly appreciated, -feri