2016-09-01 24 views
0

我有以下gradle這個構建嘗試ExpandProperties在filesMatching我gradle這個建

./build.gradle

defaultTasks 'build' 

task build(type: Copy){ 

    // read the properties from the versions.properties file 
    Properties props = new Properties() 
    props.load(new FileInputStream("../versions.properties")) 
    props.each() { k, v -> 
     ant.properties[k] = v 
    } 

    // copy files and replace placeholders 
    from('ansible'){ 
     filesMatching('**/*.ini') { 
      filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.project) 
     } 
     filesMatching('**/*.yml') { 
      println it 
      filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.project) 
     } 
     filesMatching('**/*.xml') { 
      println it 
      filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.project) 
     } 
    } 

    into 'build/pkg/ansible' 

    includeEmptyDirs = true 

} 

我要全部替換 「$ {} VARIABLENAME」 與價值的定義../versions.properties爲所有* .xml,* .ini和* .yml文件中的變量,並將所有文件複製到新文件夾。

例如: ../versions.properties

versionA=1.3 
versionB=2.3 

./ansible/example-file.yml

replace this version. => ${versionA} 

在./build/pkg/ansible/example-預期輸出file.yml

replace this version. => 1.3 

上述內容的結果是所有文件都被複制到右邊地點,但沒有進行任何財產更換。 :-(

哪裏是我的錯誤?

乾杯, d。

回答

0

它實際上沒有工作的expcected。我錯過了gradle這個 「複製」 任務不改寫爲默認值。

指定任務如下,解決了我的問題:

task build(type: Copy, overwrite: true){ 
... 
} 

乾杯, d