我如何从文件中以编程方式设置gradle依赖项
我的build.gradle中有这个
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
...
}
我想从文件中添加更多依赖项,如下所示
[
{env: "runtime", lib : "com.h2database:h2"},
{env: "runtime", lib : "mysql:mysql-connector-java:5.1.29"}
]
有人可以帮我吗,我是gradle的初学者,我需要完成一个任务,但我却不知道该怎么做
最佳答案
您可以这样做:
dependencies {
def configFile = file('db.config.json');
def json = new groovy.json.JsonSlurper().parseText(configFile.text)
json.each {
"$it.env"(it.lib)
}
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
...
}
关于grails - 如何以编程方式设置gradle依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43665015/