[GRADLE-1885] Jar task should not create build/tmp/x directory when it's not executed Created: 02/Nov/11 Updated: 04/Jan/13 Resolved: 06/Dec/11 |
|
Status: | Resolved |
Project: | Gradle |
Affects Version/s: | 1.0-milestone-3 |
Fix Version/s: | 1.0-milestone-7 |
Type: | Bug | ||
Reporter: | Matias Bjarland | Assignee: | Luke Daley |
Resolution: | Fixed | Votes: | 0 |
Description |
SYMPTOM build.gradle task bar(type: Jar) { from "somewhere" into "somewhereelse" } and the following gradle execution: command line $ gradle tasks we get the following resulting directory structure: result $ tree . ├── build │ └── tmp │ └── bar └── build.gradle 3 directories, 1 file note that we started from an empty directory. CAUSE Jar.groovy //Jar.groovy in gradle source public class Jar extends Zip { <snip> Jar() { extension = DEFAULT_EXTENSION manifest = new DefaultManifest(project.fileResolver) // Add these as separate specs, so they are not affected by the changes to the main spec metaInf = copyAction.rootSpec.addFirst().into('META-INF') metaInf.addChild().from { MapFileTree manifestSource = new MapFileTree(temporaryDir) manifestSource.add('MANIFEST.MF') {OutputStream outstr -> Manifest manifest = getManifest() ?: new DefaultManifest(null) manifest.writeTo(new OutputStreamWriter(outstr)) } return new FileTreeAdapter(manifestSource) } copyAction.mainSpec.eachFile { FileCopyDetails details -> if (details.path.equalsIgnoreCase('META-INF/MANIFEST.MF')) { details.exclude() } } } note among other things the 'temporaryDir' variable access. This comes from a super class a bunch of inheritance levels up: AbstractTask.java public File getTemporaryDir() { File dir = getServices().get(TemporaryFileProvider.class).newTemporaryFile(getName()); dir.mkdirs(); return dir; } notice the 'dir.mkdirs()'. So to summarize: just by instantiating the Jar task class we will create the directory structure described above. This is independent of whether we have elected do disable the jar task entirely, excluded it from the execution graph, added an onlyIf clause etc etc. Note that we get the same result with the following build file: build.gradle
apply plugin: 'java'
and just executing 'gradle tasks'. I think this behavior is unexpected and undesirable. In large multi-project builds where we want to leave directories without sources or resources well alone, this becomes a serious issue. In addition, creating a clean workaround by selectively deleting the build directory only when it was erroneously created by the jar task is actually non-trivial. How do you figure out if the Jar task erroneously created the directory? And if it did, where do you add the code to remove the directory? jar.doLast doesn't work as (in my specific example) I have disabled the jar task and jar.doLast is therefore not executed. Adding this to assemble.doLast works but gets hairy with the state management to only do this when the jar task did the wrong thing. WORKAROUND stupid workaround assemble.doLast { if (!fileTree(dir: buildDir).find { it.isFile() } ) { println "no files present in ${project.path} build dir $buildDir, deleting it" delete(buildDir) } } POSSIBLE SOLUTION |
Comments |
Comment by Matias Bjarland [ 07/Nov/11 ] |
Verified, still an issue in 1.0-milestone-5 |
Comment by Luke Daley [ 06/Dec/11 ] |
Fixed in m7. https://github.com/gradle/gradle/commit/8ec092058a66c2155396644df5ce0ba3d8854232 |