Hi,
I have a Java project where the build process goes something like this:
- compile and run tests as usual * call an external Java program that packages the class files and some other stuff into a zip with a specific structure (not a normal jar)
The external Java program (which is an executable jar called toolkit.jar) produces zips with a version number and timestamp in the file name, something like “MyBlade-1.0.0-20130115-174704.zip”. I won’t know the name of the file that it produces until after the program has run.
This is what I have in my build script:
task exportBlade(type: Exec, dependsOn: test ) {
executable "java"
args '-jar'
args "${project.rootDir}/build/toolkit.jar"
args 'export'
args "${project.projectDir}"
args '-inputFiles'
args sourceSets.main.output.classesDir
args '-outputDir'
args "${buildDir}/distributions"
}
}
artifacts {
bladeZip fileTree("${buildDir}/distributions").files.toArray()[0]
}
build.dependsOn exportBlade
The idea is that when the exportBlade task runs it will call the Java program (toolkit.jar) and output the zip into the ${buildDir}/distributions directory. I don’t know what filename that zip will have so in my artifacts section I use a fileTree to just grab the first file in that directory. This relies on not having more than one file in the ${buildDir}/distributions directory, but that is taken care of elsewhere.
The problem is that Gradle evaluates my fileTree when it compiles the build script, at which point the ${buildDir}/distributions directory is empty. So it fails with this error:
FAILURE: Build failed with an exception.
* Where:
Build file 'D:\Development\Motifs\fxmotif\server\build.gradle' line: 60
* What went wrong:
A problem occurred evaluating project ':server'.
> 0
How can I define my artifact to be a file that is generated by a task that runs during the build when that file has a dynamic name that I don’t know at compile time?
Cheers