Incremental Compile in Gradle not working when using file from classpath

安稳与你 提交于 2019-12-25 02:32:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!