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.