--Define a task to ZIP archive a set of project files in Gradle --Operation check environment: Gradle 6.6 + Java 14 (AdoptOpenJDK 14.0.2)
build.gradle
plugins {
id 'java'
}
repositories {
mavenCentral()
}
version = '1.2.3'
dependencies {
//Specify the library to use
implementation 'com.google.guava:guava:29.0-jre'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
}
//Define a task to ZIP archive a set of project files
task myZip(type: Zip) {
//Directory to output ZIP file
destinationDirectory = file('..') //Keep it one level higher
//File name to archive
archiveFileName =
'myapp-' +
archiveVersion.get() + '-' +
new Date().format('yyyyMMdd_HHmmss_SSS') + '.zip'
//Project directory
from '.' //Current directory
//Gradle generated file storage(build directory)Or
// .Don't include hidden directories such as gradle in your ZIP file
excludes = ['build', '.*']
}
It is assumed that not only the source code but also text files and image files are included in the project set.
$ find .
.
./foodir
./foodir/foo.jpg
./foodir/foo.png
./foo.txt
./build.gradle
./src
./src/test
./src/test/resources
./src/test/resources/mytest.properties
./src/test/java
./src/test/java/myapp
./src/test/java/myapp/AppTest.java
./src/main
./src/main/resources
./src/main/resources/myapp.properties
./src/main/java
./src/main/java/myapp
./src/main/java/myapp/App.java
Execute the defined task myZip.
$ gradle myZip
BUILD SUCCESSFUL in 651ms
1 actionable task: 1 executed
Check the contents of the ZIP file.
$ unzip -l ../myapp-1.2.3-20200816_091726_068.zip
Archive: ../myapp-1.2.3-20200816_091726_068.zip
Length Date Time Name
--------- ---------- ----- ----
0 08-16-2020 07:45 foodir/
14526 08-16-2020 09:16 foodir/foo.jpg
18136 10-18-2019 18:50 foodir/foo.png
84 08-16-2020 09:14 foo.txt
998 08-16-2020 08:51 build.gradle
0 08-16-2020 06:59 src/
0 08-16-2020 06:59 src/test/
0 08-16-2020 09:16 src/test/resources/
9 08-16-2020 09:17 src/test/resources/mytest.properties
0 08-16-2020 06:59 src/test/java/
0 08-16-2020 06:59 src/test/java/myapp/
357 08-16-2020 06:59 src/test/java/myapp/AppTest.java
0 08-16-2020 06:59 src/main/
0 08-16-2020 09:16 src/main/resources/
9 08-16-2020 09:16 src/main/resources/myapp.properties
0 08-16-2020 06:59 src/main/java/
0 08-16-2020 06:59 src/main/java/myapp/
286 08-16-2020 06:59 src/main/java/myapp/App.java
--------- -------
34405 18 files
Recommended Posts