我有两个不同的Web应用程序配置文件:“ test”和“ dev”,然后有2个包含文件的文件夹/opt/myApp/dev
和/opt/myApp/test
。
我需要构建我的App,将参数发送到gradle,以便根据配置文件定义路径。
在我的春季application-context.xml中,我有以下内容:
<bean id="myBean" class="com.myClass">
<property name="locations" value="file:/opt/myApp/${profile}"</property>
</bean>
如果我做不到这样的话会很好的:
gradle build -Pprofile
Gradle脚本可以完成工作
我查看了文档和stackoverflow,发现了有关过滤器的信息。但是我无法使它工作。
我正在尝试这个和其他类似的东西。
可能有一种更清洁的方法,但是类似:
application-context.xml:
<bean id="myBean" class="com.myClass">
<property name="locations" value="file:/opt/myApp/@profile@"</property>
</bean>
build.gradle:
import org.apache.tools.ant.filters.*
apply plugin: 'java'
if (! hasProperty("profile")) {
ext.profile = "dev"
}
processResources {
filter(ReplaceTokens, tokens: [profile: profile])
}
然后像这样调用它:
gradle -Pprofile=test
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句