簡體   English   中英

為什么`gradle`在每個子項目中都執行`ant.replaceregexp`?

[英]Why `gradle` is executing `ant.replaceregexp` in every subproject?

我有一個具有此結構的java gradle項目:

EarApp
|
\---> WarA/trunk
|     |
|     |- build.gradle
|     ...<src and config>
|
\---> WarB/trunk
|     |
|     |- build.gradle
|     ...<src and config>
|
\---> WarC/trunk
|     |
|     |- build.gradle
|     ...<src and config>
|
|- build.gradle
|- settings.gradle

我的settings.gradle是:

include "WarA"
include "WarB"
include "WarC"

project(":WarA").projectDir          = file("WarA/trunk")
project(":WarB").projectDir          = file("WarB/trunk")
project(":WarC").projectDir          = file("WarC/trunk")

子項目中的每個build.gradle都包含:

import org.tmatesoft.svn.core.wc.*
def getSvnRevision(){
    ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
    SVNClientManager clientManager = SVNClientManager.newInstance(options);
    SVNStatusClient statusClient = clientManager.getStatusClient();
    SVNStatus status = statusClient.doStatus(projectDir, false);
    SVNRevision revision = status.getRevision();
    return revision.getNumber();
}


def replaceTokens() {
    ant.replaceregexp(
      file:  "./src/main/resources/messages/text.properties",
        match:   "application.revision=(.*)",
        replace: "application.revision=rev_" + getSvnRevision(),
        byline:  "true"
    )
}


war {
  replaceTokens() // Update rev number
  baseName = nome

  from('config') {
    include 'ibm-web-ext.xml'
    into 'WEB-INF'

    manifest {
      attributes("Application-Name": baseName,
                 "Implementation-Version": versione + 'rev_' + getSvnRevision())
    }
  }
}

在執行gradle -p WarA/trunk wargradle WarA:war ,會正確構建WarA.war,但我期望ant僅更新./src/main/resources/messages/text.properties的./src/main/resources/messages/text.properties。

相反,我得到每個子項目都更新了./src/main/resources/messages/text.properties文件。

我想念什么?

doFirst{}內移動replaceTokens()將達到目的。

war {
  doFirst{
    replaceTokens() // Update rev number
  }
  baseName = nome

  from('config') {
    include 'ibm-web-ext.xml'
    into 'WEB-INF'

    manifest {
      attributes("Application-Name": baseName,
                 "Implementation-Version": versione + 'rev_' + getSvnRevision())
    }
  }
}

此處參考: https : //discuss.gradle.org/t/what-difference-between-configuration-setting-and-dofirst-dolast/23406

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM