user3414265
user3414265

Reputation: 23

Gradle JAR files in a folder recursively

How can I JAR a folder and all of it's sub directories and files in a simple JAR? I tried something like this and it does not work.

task jarVrCore(type: Jar, description: 'JARs core part of the project') {
    doLast {
        archiveName = "vasasdasasdasd"
        from "${projectDir}"
        println "${vrCoreSourceDir}"
        destinationDir = file("${dirTmpLibsVr4}")
    }
}

I always get an empty JAR with only the manifest.

Upvotes: 2

Views: 500

Answers (1)

Lukas Körfer
Lukas Körfer

Reputation: 14543

The problem is that all of your task configurations are applied too late. You are using a doLast closure, which is executed after the actual task action (for a Jar task: the creation of the .jar file).

Normally, all task configuration is done directly inside the task configuration closure:

task jarVrCore(type: Jar, description: 'JARs core part of the project') {
    archiveName = "vasasdasasdasd"
    from "${projectDir}"
    println "${vrCoreSourceDir}"
    destinationDir = file("${dirTmpLibsVr4}")
}

If you need to apply configuration after other tasks have been executed, use a doFirst closure.

Please note, that using the example above, the println statement will be executed during configuration phase and therefore on each Gradle invocation, whether the task jarVrCore is executed or not.

Upvotes: 2

Related Questions