我有这样的属性的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。我怎么能这样做?
答案 0 :(得分:5)
假设您的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"
}
}