我有这样的属性yml文件:
spring:
application:
name: auth module
profiles:
active: prod
在我的gradle.build中:
jar {
baseName = 'auth-module-dev'
version = '0.1.2'
}
我想构建像auth-module-%profile_name%.jar这样的jar.我怎样才能做到这一点?
解决方法:
假设您的yaml文件名称为cfg.yaml
不要忘记在yaml的开头添加—
---
spring:
application:
name: auth module
profiles:
active: prod
的build.gradle:
defaultTasks "testMe"
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.yaml', name: 'snakeyaml', version: '1.19'
}
}
def cfg = new org.yaml.snakeyaml.Yaml().load( new File("cfg.yaml").newInputStream() )
task testMe( ){
doLast {
println "make "
println "profile = ${cfg.spring.profiles.active}"
assert cfg.spring.profiles.active == "prod"
}
}