Home > OS >  Gradle zip task: Specify destination path inside zip file individually
Gradle zip task: Specify destination path inside zip file individually

Time:12-15

Here's my project file layout

ROOT
|-src
| |- main
|    |- java
|    |   \- [rest of java files]
|    |- scripts
|        \- run.bat
|-build
|-build.gradle
|-settings.gradle

What I'm trying to do is to create a 'dist' Gradle task that will create a zip file under dist folder with the following internal layout:

ROOT
|
:
|- dist
    \- myproject.zip
        |-lib
        | |-myapp.jar
        \-bin
          |-run.bat

Here's my build.gradle

plugins {
  id 'java'
}

/* other tasks */

tasks.register('dist', Zip) {
  dependsOn('build')
  from "build/libs/myapp.jar"
  into "lib"

  from "src/main/scripts/run.bat"
  into "bin"  // <<<--- this wont work as it will overwrite "lib" as destination

  archiveName "myproject.zip"
  destinationDir(file('dist'))
}

My problem is that Zip task is only allow for one 'into' destination. What I need is to specify the destination of each and every source individually.

Am I doing this correctly?

CodePudding user response:

you can use the 'distribution' plugin ; that would give most of your zip needs ; just need to add additional paths see https://docs.gradle.org/current/userguide/distribution_plugin.html#header

  • Related