问题
I am trying to build some kind of support for a maven-like dependency-management for our project. For this I add the pom I want to inherit from as a classpath dependency in the buildscript. I wrote a plugin that adds a task "inherit" that takes a file as Input and parses it and puts the dependencies from that pom into a map. The task is started in the apply method of the plugin where I get the pom from the classpath.
static class InheritDependencyTask extends DefaultTask {
@InputFile
File pomForInheritance
@Input
def dependencyMap
@TaskAction
public void processPom(){
def parsedPom = new XmlSlurper().parse(pomForInheritance)
parsedPom.dependencyManagement.dependencies.dependency.each { dependency ->
def key = dependency.groupId.text() + ":" + dependency.artifactId.text()
String version = dependency.version.text()
if (version.contains("\$")) {
String propertyKey = version.replace("\${", "").replace('}', '')
version = parsedPom.properties.getAt(propertyKey)
}
dependencyMap.put(key, version)
}
}
}
In the apply method of the plugin I add the task and make compile depend on it with:
project.compileJava.dependsOn("inherit")
project.task("inherit", type: InheritDependencyTask){
dependencyMap = project.dependencyMap
pomForInheritance = project.buildscript.configurations.classpath.find { File dependency -> (dependency.name.contains(MY_ARTIFACT_ID) )}
}
At some other point I loop through my dependencies and change the versions according to the ones I got from the pom.
This all seems to work. But compileJava is never up to date. It always has to recompile. Am I doing something wrong or is gradle not able see that the classpath-file didn't change?
Regards, arne
来源:https://stackoverflow.com/questions/22784643/incremental-compile-in-gradle-not-working-when-using-file-from-classpath