Copy of configuration files appears to have a bug

not-a-bug

(Justin) #1

Copy of configuration files appears to have a bug when preceded by clean:

$ ./gradlew clean copyResources
:clean
:copyResources UP-TO-DATE

BUILD SUCCESSFUL

Total time: 3.595 secs
$ ls build
ls: cannot access 'build': No such file or directory

Works as expected when each task run separately:

$ ./gradlew clean
:clean

BUILD SUCCESSFUL

Total time: 4.681 secs
$ ./gradlew copyResources
:copyResources

BUILD SUCCESSFUL

Total time: 1.883 secs
$ ls build
LICENSE  MANIFEST.MF  tmp/

Gradle Version: 3.1
Operating System and JVM version: Windows 10 and Oracle Java 1.8.0_102
Is this a regression? Unsure.

Here’s the build script:

repositories {
jcenter()
}

configurations {
foo
}

dependencies {
foo ‘log4j:log4j:1.2+’
}

task clean(type: Delete) {
delete buildDir
}

task copyResources(type: Copy) {
into buildDir
dependsOn configurations.foo
inputs.files configurations.foo
outputs.files “${buildDir}/MANIFEST.MF”, "${buildDir}/LICENSE"
from (zipTree(configurations.foo.asPath).files) {
include 'MANIFEST.MF’
include ‘LICENSE’
}
}


(Stefan Oehme) #2

The copy task as shown is broken. It unpacks at configuration time, so the clean task deletes the unpacked files at execution time, leaving the copy with no source files. Also make sure that tasks don’t have overlapping output directories. I assume you only used the buildDir for demonstration purposes. It is pretty much never what you should use in a real scenario. You were probably trying to do something like this:

task unpackSomeStuff() {
  def outputDir = "build/unpackedStuff"
  inputs.files configurations.foo
  outputs.dir outputDir
  doLast {
    copy {
      into outputDir
      from(zipTree(configurations.foo.singleFile)) {
        include ....
      }
    }
  }
}

(Don Henry) #3

You need to apply the base plugin at the top of your build.gradle.

This line:
apply plugin: ‘base’


(Stefan Oehme) #4

That won’t make a difference for this example. The problem was unpacking at configuration time as I explained above.


(Justin) #5

At first, I thought you meant that the copy task is executed at configuration time which confused me. But now I understand that the unpacking of source files, configurations.foo, is what happens at configuration time.

$ ls build/tmp/expandedArchives/log4j-1.2.17.jar_cvl7295ws1wt3f7a4uj2fe3du/
META-INF/ org/

Then clean executes and removes these files before copy. Thanks for the help!