【发布时间】:2016-12-18 04:48:15
【问题描述】:
我正在考虑从 maven 迁移到 gradle,在我们当前的设置中,我们有一个主 pom 来定义我们所有的版本依赖项。
项目名称是 master-pom,sn-ps 如下:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils-version}</version>
</dependency>
.... 稍后在文件中,我们按照以下方式定义一些内容:
<properties>
<commons-beanutils-version>1.9.1</commons-beanutils-version>
</properties>
现在,这就是我目前所拥有的:
plugins {
id "com.github.johnrengelman.shadow" version "1.2.4"
id "nebula.dependency-recommender" version "3.7.0"
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'nebula.dependency-recommender'
apply plugin: "com.github.johnrengelman.shadow"
version = '1.0.0-SNAPSHOT'
sourceCompatibility = '1.8'
description = """best-service-ever"""
repositories {
mavenLocal()
maven { url 'https://repo.server.com/nexus/content/groups/public'
credentials {
username 'username'
password nexusPassword
}
}
mavenCentral()
jcenter()
}
dependencyRecommendations {
mavenBom module: 'biz.company.name:master-pom:1.0.0-SNAPSHOT'
}
dependencies {
... some dependencies
compile 'biz.company.name:db-schema'
}
此时它将选择名为 ${db-version} 的版本并使用 build-maven 中正确定义的版本。问题是,我需要用特定版本覆盖该版本。
我尝试将值放在 gradle.properties 中,但这样做有问题。
db-version 不受 gradle 支持,因为它将 - 解释为算术运算。我改为尝试将值定义为
db_version=0.0.1700
这似乎可行,但我如何设置它以覆盖 $db-version 值。我想避免必须明确设置版本:在每个工件中。
我的理想方案是允许我简单地覆盖来自 bom 文件的属性。
以前有人遇到过这个问题吗?或者有什么解决办法?
【问题讨论】:
-
你是指BOM还是POM?
-
Gradle 似乎将这种模式称为 bom,但它基本上是一个发布用于管理依赖关系的 maven pom 文件。引用:gradle.org/migrating-a-maven-build-to-gradle。 """Maven 允许您在标签内的单独 POM 中指定依赖项列表。然后可以将这种特殊类型的 POM(BOM)导入其他 POM,以便您在所有项目中拥有一致的库名称和版本。"" "
-
我确实发现这种模式似乎有效,虽然它有点脆弱。