How to load yml propery to gradle

前端 未结 1 1591
北海茫月
北海茫月 2021-01-01 01:21

I have yml file with such property:

spring:
  application:
    name: auth module
  profiles:
    active: prod

In my gradle.build:



        
相关标签:
1条回答
  • 2021-01-01 01:42

    assume your yaml file has name cfg.yaml

    don't forget to add --- at the beginning of 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"
        }
    }
    
    0 讨论(0)
提交回复
热议问题