我所希望的是一个简单的问题,我没有运气找到答案。
我希望通过替换某些变量,让build.gradle文件在Spring应用程序中设置版本。这项工作如广告所示:
def tokens = [
"version": 'project.version.toString()',
"projectName": project.name,
"groupId": rootProject.group,
"artifactId": project.name
]
processResources{
filter (ReplaceTokens, tokens: tokens)
outputs.upToDateWhen{ false }
}然而,这段代码也替换了java密钥存储中的一些内容,我在资源中也包含了这些东西,这会破坏它。当我使用ant排除任何不是我想要替换的文件时,没有任何其他文件会被复制。即包括“*.properties”
是否有一种方法只对某些文件执行令牌替换,同时仍然复制资源目录中的其余文件?是否需要为非属性文件定义单独的复制任务?
谢谢!
发布于 2016-07-26 21:07:26
解决方案是在执行任务processReousrces时跳过任何二进制文件。例如,我使用expand()将文本文件中的标记替换为在gradle脚本中计算的值。所以,
下面是如何跳过src/main/resources/certs/目录下的文件。doLast()保证jks文件在资源结束时被复制到适当的位置。
ext {
commit = 'git rev-parse --short HEAD'.execute().text.trim()
branch = 'git rev-parse --abbrev-ref --symbolic HEAD'.execute().text.trim()
}
/**
* Processes the resources, excluding the certs while building.
*/
processResources {
// Exclude the certs files to be processed as text
exclude "**/certs/*"
expand(
timestamp: new Date(),
commit: commit,
branch: branch,
version: project.version
)
// Copy the jks file to the resources (classpath)
doLast {
copy {
from "src/main/resources/certs/server.jks"
into "$buildDir/classes/main/certs"
}
}
}发布于 2019-01-27 18:43:28
processResources {
filesNotMatching("**/certs/*") {
expand(
timestamp: new Date(),
commit: commit,
branch: branch,
version: project.version
)
}
}我今天遇到了同样的问题,我在https://stackoverflow.com/a/36731250/2611959上找到了这个解决方案
https://stackoverflow.com/questions/36988438
复制相似问题