0
我想在构建过程中用Gradle替换log4j2.xml中的值。我找到了一种方法:如何使用Gradle替换log4j2.xml?
task reaplaceInLogFile {
String apiSuffix = System.properties['apiSuffix'] ?: ''
println "In my task"
String contents = file('src/main/resources/log4j2.xml').getText('UTF-8')
println "File found"
contents = contents.replaceAll("svc0022_operations", "svc0022_operations${apiSuffix}")
new File('src/main/resources/log4j2.xml').write(contents, 'UTF-8')
}
但是,这也改变了源文件的永久性,我不想这样做。我想更改将仅包含在构建zip中的log4j2.xml。我知道我可以使用这样的事情:
tasks.withType(com.mulesoft.build.MuleZip) { task ->
String apiSuffix = System.properties['apiSuffix'] ?: ''
task.eachFile {
println name
if (name == 'mule-app.properties') {
println "Expanding properties for API Version suffix: ${apiSuffix}"
filter { String line ->
line.startsWith("${serviceId}.api.suffix") ? "${serviceId}.api.suffix=${apiSuffix}" : line
}
}
但我不知道什么是log4j2文件的类型。如果还有另一种方法可以做到这一点,我会很感激!
我们使用的是Mule gradle插件。
谢谢你的回答。不幸的是,log4j2.xml不在MuleZip任务的集合中。这是任务代码https://github.com/mulesoft-labs/mule-gradle-plugin/blob/master/src/main/groovy/com/mulesoft/build/MuleZip.groovy –
正如我所说的。修改包装'log4j2.xml'文件的任务。我需要看到你的'build.gradle'和'log4j2.xml'文件的路径来建议一个具体的任务来修改。 – Vampire
我们的log4j2.xml标准地位于“src \ main \ resources \ log4j2.xml”下面这是我们的build.gradle:https://www.dropbox.com/s/iuv4j9htpseyed4/build.gradle?dl=0 –