I have a problem that I can’t reproduces on Windows. It can be reproduces on Linux but only sometimes. It is vary random.
The problem is that a task is considered up-to-date when it is not.
I have two project; ‘Convert’ witch depends on SQLSource’.
The problem is that sometimes the task ‘makeAntlrOutputDir’ is up-to-date even if the folder does not exist. And sometimes is it not up-to-date when the folder is missing. which is the behavior I like.
The result is that the task *generateSqlParserAntlr’ fails because some folders are missing.
The commands that are run are:
gradlew clean
gradlew build
When the build first fails it fails consistently there after.
If I then changes a build files and run the commands again, then everything is fin. But only for some time and it goes back to failing.
Am I doing something wrong or this a bug?
I’m worried about the inconsistency.
Convert/build.gradle
import java.text.SimpleDateFormat
apply plugin: 'java'
sourceCompatibility = 1.7
targetCompatibility = 1.7
javadoc.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
dependencies {
compile project(':SQLSource')
testCompile 'junit:junit:4.12'
}
sourceSets {
main {
java.srcDirs = ['src']
}
}
SQLSource/build.gradle
apply plugin: 'java'
ext.antlr4 = [
generatedDir : 'target/generated-sources/antlr4',
sqlParserSourceDir : 'src/dk/xact/sqlparser',
sqlParserDestDir : 'target/generated-sources/antlr4/dk/xact/sqlparser',
sqlParserGrammarPackage : 'dk.xact.sqlparser'
]
sourceCompatibility = 1.7
targetCompatibility = 1.7
javadoc.options.encoding = 'UTF-8'
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
}
configurations {
antlr
}
dependencies {
compile 'org.antlr:antlr4:4.5'
testCompile 'junit:junit:4.12'
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.sqlParserDestDir).mkdirs()
}
outputs.dir antlr4.sqlParserDestDir
}
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
// TODO: Tweak the outputs collection so it is correct with combined grammars as well as separate Lexer and Parser grammars.
outputs.dir antlr4.sqlParserDestDir
}
compileJava {
dependsOn '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'
}
Gradlew -v
Gradle 3.2
Build time: 2016-11-14 12:32:59 UTC
Revision: 5d11ba7bc3d79aa2fbe7c30a022766f4532bbe0f
Groovy: 2.4.7
Ant: Apache Ant™ version 1.9.6 compiled on June 29 2015
JVM: 1.7.0_80 (Oracle Corporation 24.80-b11)
OS: Windows 7 6.1 amd64