Giriş
Açıklaması şöyle
Sometimes we might need to replace one or more files in an existing archive file. The archive file could be a zip, jar, war or other archive. Without Gradle we would unpack the archive file, copy our new file into the destination directory of the unpacked archive and archive the directory again. To achieve this with Gradle we can simply create a single task of type Zip. To get the content of the original archive we can use the project.zipTree method. We leave out the file we want to replace and define the new file as replacement. As extra safeguard we can let the tsak fail if duplicate files are in the archive, because of our replacement.archiveBaseName Alanı
Modul ismi ile aynıdır. Property olduğu için get() olarak kullanılmalıdır
Örnek
Şöyle yaparız. Böylece eğer module ismi foo ise "foo.zip" içinde "foo/scripts" diye bir dizin oluşur
//Create a new zip file task scriptsZip(type: Zip) { archiveAppendix = 'scripts' from 'scripts' into "${archiveBaseName.get()}/scripts" } assemble.dependsOn('scriptsZip')
Örnek
Açıklaması şöyle
The following code shows an example of a task to replace a README file in an archive sample.zip using Groovy and Kotlin DSL.
Şöyle yaparız
// Register new task replaceZip of type org.gradle.api.tasks.bundling.Zip.tasks.register("replaceZip", Zip) {archiveBaseName = "new-sample"destinationDirectory = file("${buildDir}/archives")// Include the content of the original archive.from(zipTree("${buildDir}/archives/sample.zip")) {// But leave out the file we want to replace.exclude("README")}// Add files with same name to replace.from("src/new-archive") {include("README")}// As archives allow duplicate file names we want to fail// the build when that happens, because we want to replace// an existing file.duplicatesStrategy = "FAIL"}
archiveFileName Alanı
Zip dosyasının ismini belirtir
Örnek
resources dizinini zip'lemek için şöyle yaparız
task packageDistribution(type: Zip) { archiveFileName = "vitesstestservertemplate.zip" destinationDirectory = file("$buildDir/libs") from "$buildDir/resources/main" } assemble.dependsOn packageDistributionarchiveAppendix Alanı
"module ismi + archiveAppendix " şeklinde yeni bir zip dosyası oluşturur. Açıklaması şöyle.
The appendix part of the archive name, if any.
Örnek
Şöyle yaparız
task scriptsZip(type: Zip) { archiveAppendix = 'scripts' from 'scripts' into "${archiveBaseName}/scripts" } assemble.dependsOn('scriptsZip')
Hiç yorum yok:
Yorum Gönder