如何加载yml propery到gradle [英] How to load yml propery to gradle
问题描述
spring:
应用程序:
名称:auth模块
配置文件:
active:prod
在我的gradle.build中:
jar {
baseName ='auth-module-dev'
version ='0.1.2'
}
我想构建像auth-module-%profile_name%.jar这样的jar。假设你的yaml文件有名称 不要忘记在yaml的开头添加 build.gradle: I have yml file with such property: In my gradle.build: I want to build jars like auth-module-%profile_name%.jar. How can I do this? assume your yaml file has name don't forget to add build.gradle:
这篇关于如何加载yml propery到gradle的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! cfg.yaml $ c $ c
$ b ---
---
spring:
应用程序:
名称:auth模块
配置文件:
active:prod
defaultTaskstestMe
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath组:'org.yaml',名称:'snakeyaml',版本:'1.19'
}
}
def cfg = new org.yaml。 snakeyaml.Yaml()。load(new File(cfg.yaml)。newInputStream())
task testMe(){
doLast {
printlnmake
printlnprofile = $ {cfg.spring.profiles.active}
assert cfg.spring.profiles.active ==prod
}
}
spring:
application:
name: auth module
profiles:
active: prod
jar {
baseName = 'auth-module-dev'
version = '0.1.2'
}
cfg.yaml
---
at the beginning of yaml---
spring:
application:
name: auth module
profiles:
active: prod
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"
}
}