我的项目在源代码中有一个.zip文件,我想把它放在文件夹1.1.0 / deployment下的appserver.zip文件中。此.zip文件再次捆绑在.tar文件中。
注意:这个项目不是JAVA / Groovy项目,即没有java程序或groovy程序
以下是我的build.gradle,它正在创建正确的.zip(包含正确的文件夹/源.zip文件)和包含appserver.zip的.tar文件:
// Let say $projName, $folderArtifactoryVersion or etc variables used in the following script - are set correctly to a valid value.
task createZipFile( type: Zip) {
// Create artifact directory
def dirName = "build/folderDist"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "appserver.zip"
println ''
println 'bundleArchiveName: ' + archiveName
into( '1.1.0/deployment' ) {
from( "cognos/Integration/Deployment" )
include( 'SomeCognos_deploy.zip' )
}
}
task createTarFile( type: Zip) {
dependsOn createZipFile
def projName = "dircognosreporting"
def dirParent = "build/folderArts"
// Create artifact directory
def dirName = "$dirParent/com/truven/folder/$projName/$folderArtifactoryVersion"
def dirDist = new File( dirName )
dirDist.mkdirs()
destinationDir dirDist
archiveName "dirCognosReporting-${folderArtifactoryVersion}.tar"
println ''
println 'bundleArchiveName: ' + archiveName
println ''
into( '' ) {
from( "build/folderDist" )
include( 'appserver.zip' )
}
}
build {
dependsOn clean
dependsOn createTarFile
}
Gradle构建日志显示以下内容:
-bash-3.2$ /production/gradle/AKS/gradle-1.6/bin/gradle clean build
Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.
Deprecated dynamic property: "folderArtifactoryVersion" on "root project 'dirCognosReporting'", value: "1.1.0.5".
bundleArchiveName: appserver.zip
bundleArchiveName: dirCognosReporting-1.1.0.5.tar
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
BUILD SUCCESSFUL
Total time: 5.117 secs
-bash-3.2$
我的2:s:
为什么createZipFile和createTarFile中定义的println消息是在第一阶段打印的,甚至在清理之前。如果我使用任务构建<< {...}然后 - 正如预期的那样,我得到的任务构建已经存在。如果我只使用build<< {....},我得到了不同的行为。
由于构建结果在build / folderDist和build / folderArts文件夹下给了我我需要的东西,我现在不太担心上面的子弹,但是我该怎么办,所以我不要请看输出中的以下行(因为我的源代码中没有与java相关的任何内容)。为什么,gradle只是不做 - createZipFile,createTarFile然后优雅地退出?
*
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:checkstyleMain UP-TO-DATE
:findbugsMain UP-TO-DATE
:pmdIntegrationTest UP-TO-DATE
:pmdMain UP-TO-DATE
:pmdTest UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:createZipFile
:createTarFile
:build
*
答案 0 :(得分:4)
ad 1.因为您在配置阶段而不是执行阶段进行打印。如果您希望println
语句在执行任务时执行,请使用doFirst { ... }
或doLast { ... }
进行包装。
ad 2.某人(例如父级构建脚本)正在将java
,pmd
,checkstyle
和findbugs
插件应用于此项目。摆脱这一切。但要保留clean
任务,请应用base
插件。要保留build
任务,请自行声明(将build { ... }
更改为task build { ... }
)。
答案 1 :(得分:0)
似乎是因为我的/init.d文件夹有somename.gradle构建,我在 allprojects {中定义了 apply plugin:'java' .....}部分。
如果我对此发表评论,我会收到一条错误,指出build()......没有或没有。