Gradle 构建 - 非 Java 项目

Aru*_*gal 1 java compilation build task gradle

我的项目在源代码中有一个 .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
}
Run Code Online (Sandbox Code Playgroud)



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$
Run Code Online (Sandbox Code Playgroud)



我的 2 ?s:

  1. 为什么在 createZipFile 和 createTarFile 中定义的 println 消息在第一阶段打印,甚至在 clean 之前。如果我使用 task build << { ... } 那么 - 正如预期的那样,我得到 task build 已经存在。如果我只使用 build << { .... },我会得到不同的行为。

  2. 由于构建结果给了我在 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
Run Code Online (Sandbox Code Playgroud)

*

Pet*_*ser 5

ad 1. 因为您是在配置阶段打印,而不是执行阶段。如果您希望将println语句作为执行任务的一部分来执行,请使用doFirst { ... }或将其包装起来doLast { ... }

广告2.有人(例如父母构建脚本)的应用javapmdcheckstyle,和findbugs插件这个项目。摆脱这一切。尽管如此clean,要保留任务,请应用base插件。要保留build任务,请自行声明(更改build { ... }task build { ... })。