Up-to-date check not working


(Chris Jones) #1

Can anybody tell me what I’m doing wrong here? Here’s my task:

task pmd << {
        // TODO The up-to-date check isn't working.
        inputs.files sourceSets.main.java
        inputs.files sourceSets.test.java
        outDir = file("$buildDirName/pmd")
        outDir.mkdirs()
        outputs.dir outDir
        println("outdir: " + outDir)
        gproj = project
        ant {
            taskdef(name: 'pmd', classname: 'net.sourceforge.pmd.ant.PMDTask',
                    classpath: configurations.pmdConf.asPath)
            pmd(rulesetFiles: 'basic,design,unusedcode',
                targetjdk: "$sourceCompatibility", shortfilenames: "true") {
                formatter(type: 'xml', toFile: outDir.path + "/pmd.xml")
                fileset(dir: projectDir.getPath()) {
                    sourceSets.main.java.each { file ->
                        include(name: gproj.relativePath(file))
                    }
                    sourceSets.test.java.each { file ->
                        include(name: gproj.relativePath(file))
                    }
                }
            }
        }
    }

When I run “gradle -i pmd”, it says this:

  :bridge:pmd  Task ‘:bridge:pmd’ has not declared any outputs, assuming that it is out-of-date.  outdir: C:\Users\chris\work\PAL-CPOF-SHELL\current\tasklearning\bridge\build\pmd  

(Chris Jones) #2

I figured it out. The inputs and outputs need to be assigned in the task container, not in the doLast container. So it should look like this:

task pmd {
        inputs.files sourceSets.main.java
        inputs.files sourceSets.test.java
        outDir = file("$buildDirName/pmd")
        outDir.mkdirs()
        outputs.dir outDir
        gproj = project
        doLast {
            ant {
                taskdef(name: 'pmd', classname: 'net.sourceforge.pmd.ant.PMDTask',
                        classpath: configurations.pmdConf.asPath)
                pmd(rulesetFiles: 'basic,design,unusedcode',
                    targetjdk: "$sourceCompatibility", shortfilenames: "true") {
                    formatter(type: 'xml', toFile: outDir.path + "/pmd.xml")
                    fileset(dir: projectDir.getPath()) {
                        sourceSets.main.java.each { file ->
                            include(name: gproj.relativePath(file))
                        }
                        sourceSets.test.java.each { file ->
                            include(name: gproj.relativePath(file))
                        }
                    }
                }
            }
        }
    }

(Peter Niederwieser) #3

That’s correct. Inputs and outputs need to be declared at configuration time.