Up to date check fails in multi project build

I have a problem with a task not being considered up-to-date in a multi project build.

I have two projects A and B.

A:build.gradle

apply plugin: 'java'

ext.antlr4 = [
    generatedDir             : 'target/generated-sources/antlr4',

    eglParserSourceDir      : 'src/dk/xact/eglparser',
    eglParserDestDir        : 'target/generated-sources/antlr4/dk/xact/eglparser',
    eglParserGrammarPackage : 'dk.xact.eglparser',


    sqlParserSourceDir       : 'src/dk/xact/sqlparser',
    sqlParserDestDir         : 'target/generated-sources/antlr4/dk/xact/sqlparser',
    sqlParserGrammarPackage  : 'dk.xact.sqlparser'
]

repositories {
    mavenCentral()
}

configurations {
    antlr
}

dependencies {
    compile 'org.antlr:antlr4:4.5'

    antlr 'org.antlr:antlr4:4.5'
}

sourceSets {
    main {
        java.srcDirs = ['src', 'target/generated-sources/antlr4']
    }
}

task makeAntlrOutputDir() {
    description 'Create output dir for Antlr.'

    doFirst {
        file(antlr4.eglParserDestDir).mkdirs()
        file(antlr4.sqlParserDestDir).mkdirs()
    }

    outputs.dir file(antlr4.eglParserDestDir)
    outputs.dir file(antlr4.sqlParserDestDir)
}

task generateEglParserAntlr(type: JavaExec, dependsOn: makeAntlrOutputDir) {
    description 'Generates ANTLR parser from EGL grammar files.'

    main = 'org.antlr.v4.Tool'
    classpath = configurations.antlr
    def grammars = fileTree(dir: antlr4.eglParserSourceDir, includes: ['**/*.g', '**/*.g4'])
    def target = file(antlr4.eglParserDestDir)

    args = [
        '-o', target,                // specify output directory where all output is generated
        '-lib', target,              // specify location of grammars, tokens files
        '-encoding', 'UTF-8',        // specify grammar file encoding; e.g., euc-jp
        '-message-format', 'antlr',  // specify output style for messages in antlr, gnu, vs2005
        '-long-messages',            // show exception details when available for errors and warnings
        '-listener',                 // generate parse tree listener (default)
        '-visitor',                  // generate parse tree visitor
        '-package', antlr4.eglParserGrammarPackage,   // specify a package/namespace for the generated code
        grammars.files
    ].flatten();

    // setup when this task is up to date.
    inputs.files grammars.files
    outputs.dir target
}

task generateSqlParserAntlr(type: JavaExec, dependsOn: makeAntlrOutputDir) {
    description 'Generates ANTLR parser from SQL grammar files.'

    main = 'org.antlr.v4.Tool'
    classpath = configurations.antlr
    def grammars = fileTree(dir: antlr4.sqlParserSourceDir, includes: ['**/*.g', '**/*.g4'])
    def target = file(antlr4.sqlParserDestDir)

    args = [
        '-o', target,                // specify output directory where all output is generated
        '-lib', target,              // specify location of grammars, tokens files
        '-encoding', 'UTF-8',        // specify grammar file encoding; e.g., euc-jp
        '-message-format', 'antlr',  // specify output style for messages in antlr, gnu, vs2005
        '-long-messages',            // show exception details when available for errors and warnings
        '-listener',                 // generate parse tree listener (default)
        '-visitor',                  // generate parse tree visitor
        '-package', antlr4.sqlParserGrammarPackage,   // specify a package/namespace for the generated code
        grammars.files
    ].flatten();

    // setup when this task is up to date.
    inputs.files grammars.files
    outputs.dir target
}

compileJava {
    dependsOn 'generateEglParserAntlr', 'generateSqlParserAntlr'

    // add Antlr generated dir to source so it can be compiled.
    source antlr4.generatedDir
}

javadoc {
    source antlr4.generatedDir
    exclude '**/*.tokens'
}

task cleanAntlr() {
    description 'deletes the Antlr generated dir.'

    doLast {
        delete antlr4.generatedDir
    }
}

clean {
    dependsOn 'cleanAntlr'
}

B:build.gradle

apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile project(':A')
}

sourceSets {
    main.java.srcDirs = ['src']
}

If i in project A runs gradle generateEglParserAntlr twice then the task “generateEglParserAntlr” is up-to-date.
If i in project B runs gradle generateEglParserAntlr twice then the task “generateEglParserAntlr” is up-to-date.

But if I run gradle generateEglParserAntlr in project A, and then gradle build in project B then generateEglParserAntlr is not up to date.

I don’t understand why the task generateEglParserAntlr up-to-date status can change just because a task is run from two different projects.

I would like that the task generateEglParserAntlr is up-to-date the second time it is run. As long as any input files has not changed.

Can anyone please explain what im duing wrong or if I have misunderstud something.

Have you run Gradle with -i, it gives information about task inputs and outputs.

I have tried with -i now. And this is what i get.

:EGLSource:generateEglParserAntlr (Thread[Daemon worker Thread 2,5,main]) started.
:EGLSource:generateEglParserAntlr
Executing task ‘:EGLSource:generateEglParserAntlr’ (up-to-date check took 0.015 secs) due to:
Value of input property ‘environment’ has changed for task ':EGLSource:generateEglParserAntlr’
Starting process ‘command ‘C:\Program Files\Java\jdk1.7.0_80\bin\java.exe’’. Working directory: C:\Users\kec\workspace_neon\ParserTool\EGLSource Command: C:\Program Files\Java\jdk1.7.0_80\bin\java.exe
-Dfile.encoding=windows-1252 -Duser.country=US -Duser.language=en -Duser.variant -cp C:\Users\kec.gradle\caches\modules-2\files-2.1\org.antlr\antlr4\4.5\af4a530e3cd7fa03636645d8077145eefac12907\antlr
4-4.5.jar;C:\Users\kec.gradle\caches\modules-2\files-2.1\org.antlr\antlr4-runtime\4.5\29e48af049f17dd89153b83a7ad5d01b3b4bcdda\antlr4-runtime-4.5.jar;C:\Users\kec.gradle\caches\modules-2\files-2.1\o
rg.antlr\antlr-runtime\3.5.2\cd9cd41361c155f3af0f653009dcecb08d8b4afd\antlr-runtime-3.5.2.jar;C:\Users\kec.gradle\caches\modules-2\files-2.1\org.antlr\ST4\4.0.8\a1c55e974f8a94d78e2348fa6ff63f4fa1fae6
4\ST4-4.0.8.jar;C:\Users\kec.gradle\caches\modules-2\files-2.1\org.abego.treelayout\org.abego.treelayout.core\1.0.1\e31e79cba7a5414cf18fa69f3f0a2cf9ee997b61\org.abego.treelayout.core-1.0.1.jar org.an
tlr.v4.Tool -o C:\Users\kec\workspace_neon\ParserTool\EGLSource\target\generated-sources\antlr4\dk\xact\eglparser -lib C:\Users\kec\workspace_neon\ParserTool\EGLSource\target\generated-sources\antlr4\dk
\xact\eglparser -encoding UTF-8 -message-format antlr -long-messages -listener -visitor -package dk.xact.eglparser C:\Users\kec\workspace_neon\ParserTool\EGLSource\src\dk\xact\eglparser\EGLLexer.g4 C:
Users\kec\workspace_neon\ParserTool\EGLSource\src\dk\xact\eglparser\EGLParser.g4
Successfully started process ‘command ‘C:\Program Files\Java\jdk1.7.0_80\bin\java.exe’’.

It is the same message everytime EGLSource:generateEglParserAntlr is not up to date.

I guess that this is the problem: “Value of input property ‘environment’ has changed for task ‘:EGLSource:generateEglParserAntlr’” But is don’t understand the problem. Is there a way to print the content of the input property ‘environment’?

This is a known bug in Gradle 3.0 and will be fixed in Gradle 3.1.

Thanks the replay. I’m looking forward to 3.1 :slight_smile: