【问题标题】:Change dependency version number in multi project gradle build在多项目 gradle build 中更改依赖版本号
【发布时间】:2018-05-02 06:16:55
【问题描述】:

我有一个包含coreclient 的多模块gradle 项目。 client 取决于 core,它的声明如下:

dependencies {
    compile project(':core')
}

如果我将coreclient 发布到Ivy 或Maven,则从clientcore 的依赖项使用当前为core 定义的确切版本(例如1.0.0)。

有办法改变吗?假设core 保证在次要版本之间兼容。因此,我希望依赖于版本 1.+,而不是 1.0.0

【问题讨论】:

  • 那么请不要犹豫,将您的解决方案放入答案中。
  • 我想知道你为什么要这样做,因为它们在多个模块之间是紧密耦合的。
  • @chenrui 就像我说的,模块保证在主要版本之间兼容。因此,您不必更新客户端以使用更新版本的核心(在一个专业内)。使用固定的版本号,这是不可能的。此外,coreclient 示例只是一个示例。真正的项目有更多的模块。

标签: maven gradle publish ivy artifacts


【解决方案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.+')
            }
        }
    }
}

【讨论】:

    猜你喜欢
    • 2023-04-08
    • 2016-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-10
    • 2018-01-12
    • 1970-01-01
    相关资源
    最近更新 更多