Using 'each' makes include global on 'jar' task


(Meikel Brandmeyer) #1

I notice the following problem in v1.10:

def someFiles = [ "some", "files" ]
  jar {
    into("subdir") {
        from(project.projectDir) {
            someFiles.each { include it }
        }
    }
}

This results in the files being added to the ‘subdir’ in the created jar file. However, they are the only files added to the jar file! I would have expected that these are added additionally to the jar file besides the normal project output.

The following gives the desired effect:

jar {
    into("subdir") {
        from(project.projectDir) {
            include someFiles
        }
    }
}

Is this a misunderstanding on my side how this should work? Or is it a bug?


(Peter Niederwieser) #2

Your syntax is unconventional, and I’m not sure if and how it is supposed to work. Have you only had this problem since 1.10? Does the following solve it?

def someFiles = [ "some", "files" ]
jar {
    into("subdir") {
        from(project.projectDir)
        someFiles.each { include it }
    }
}

(Meikel Brandmeyer) #3

Oh. Ok. I thought I saw this in an example somewhere, but I might be mistaken. I would have expected that something like the following is a reasonable thing to do.

jar {
    into("subdir") {
        from("a") {
            include "some-a-file"
        }
        from("b") {
            include "some-b-file"
        }
    }
}

Edit: I only tested with v1.10. That’s what I’m currently running.


(Meikel Brandmeyer) #4

To a certain degree, this expectation doesn’t seem to be too far off since it actually works. However, the ‘each’ + closure makes things go nuts, which is a bit surprising given the fact that the plain include works.


(Peter Niederwieser) #5

I think you are right, although you could also repeat the ‘into’ and use the syntax I used. Raised as GRADLE-2986.