gradle - 如何在gradle中参数化依赖版本?

标签 gradle dependencies

假设我在gradle构建中有一组依赖项:

dependencies {
    compile "org.springframework:spring-core:4.3.7.RELEASE"
    compile "org.springframework:spring-context:4.3.7.RELEASE"
    compile "org.springframework:spring-webmvc:4.3.7.RELEASE"
    compile "org.springframework:spring-web :4.3.7.RELEASE"
    ...
}

假设有新版本的5.0.0.RELEASE出现了。我不想在build.gradle中编辑每个依赖项。

有什么办法可以在此文件中设置一个变量,以用于所有依赖项?换句话说,我只会修改此变量的值,而不会修改所有依赖项。

最佳答案

您可以例如尝试:

apply plugin: 'java'

repositories {
  mavenCentral()
}

ext.ver = "4.3.7.RELEASE"

dependencies {
    compile "org.springframework:spring-core:$ver"
    compile "org.springframework:spring-context:$ver"
    compile "org.springframework:spring-webmvc:$ver"
    compile "org.springframework:spring-web:$ver"
}

关于gradle - 如何在gradle中参数化依赖版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42971504/

相关文章:

eclipse - Eclipse:通过gradle导入项目->找不到目标android-16

android - 动态添加dependsOn到gradle任务

java - "right"放置 WAR 依赖项的位置在哪里?

gradle - 当变量改变时重新运行 processResoures

c# - NAudio 错误 : "NoDriver calling acmFormatSuggest"

javascript - 如果对象的成员之间存在依赖关系,是否可以使用文字符号初始化对象?

gradle - Gradle任务增加版本号

java - 我可以添加打包为 .jar 以外的任何内容的 Maven 依赖项吗?

c++ - libtool: install: error: 在安装之前用上面的命令重新链接 `libmyprog.la'

c# - 如何按依赖关系对依赖对象进行排序