grails - 如何以编程方式设置gradle依赖项

标签 grails gradle groovy dependency-management

我如何从文件中以编程方式设置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/

相关文章:

flutter - 在 flutter 运行期间获取多个错误消息(与 gradle 相关)

gradle - 使用 gradle 进行依赖管理

grails - grails服务::多个项目

tomcat - 无法从 Grails 3.0.7 应用程序 war 中删除嵌入式 Tomcat

grails - Grails 中是否有首选/标准方式将表单参数绑定(bind)到域对象列表?

gradle - 设置与Docker Cloud和Spring Boot的持续集成

在 gorm/groovy 上使用 mongodb 启动时出现 springboot 初始化错误

java - 即使我在正确的域中,Selenium addCookie 也会出现无效的 Cookie 域异常

excel - Java.lang.NoClassDefFoundError :org/openxmlformats/schemas/spreadsheetml/x2006/main/ctextensionlist in groovy

validation - 我无法根据 grails 'inList' 中的 double 列表验证 double