我有一个包含 core
的多模块 gradle 项目和 client
. client
取决于 core
声明如下:
dependencies {
compile project(':core')
}
如果我发布
core
和 client
对 Ivy 或 Maven 的依赖来自 client
至core
使用当前为 core
定义的确切版本(例如 1.0.0
)。有没有办法改变它?假设
core
保证在次要版本之间兼容。所以而不是1.0.0
我希望依赖于版本 1.+
.
最佳答案
为了替换生成的 pom.xml 中的版本,我创建了一个辅助函数:
// helper function to replace dependency version in maven pom.xml
def replaceDependencyVersion(root, groupId, artifactId, version) {
// replace version
root.dependencies.dependency.findAll() { node ->
node.groupId.text() == groupId && node.artifactId.text() == artifactId
}.each() { node ->
node.version*.value = version
}
}
然后可以在发布中使用此函数来替换版本号:
// publishing
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
pom.withXml {
replaceDependencyVersion(asNode(), 'com.test', 'core', '1.+')
}
}
}
}
关于maven - 在多项目 gradle build 中更改依赖版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368119/