简体   繁体   English

在多项目Gradle构建中更改依赖版本号

[英]Change dependency version number in multi project gradle build

I have a multi module gradle project which contains core and client . 我有一个包含coreclient的多模块gradle项目。 client depends on core which is declared like this: client依赖于这样声明的core

dependencies {
    compile project(':core')
}

If I publish core and client to Ivy or Maven the dependency from client to core uses the exact version that is currently defined for the core (eg 1.0.0 ). 如果我将coreclient发布到Ivy或Maven,则从client core的依赖关系将使用当前为core定义的确切版本(例如1.0.0 )。

Is there a way to change that? 有办法改变吗? Let's say the core is guaranteed to be compatible between minor releases. 假设core在次要发行版之间是兼容的。 So instead of 1.0.0 i'd like the dependency to be to version 1.+ . 因此,我希望该版本不是1.0.0而是版本1.+

In order to replace the version in the generated pom.xml I created a helper function: 为了替换生成的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
    }
}

This function can then be used in publishing to replace the version number: 然后可以在发布中使用此功能替换版本号:

// publishing
publishing {
    publications {
        mavenJava(MavenPublication) {
            from components.java

            pom.withXml {
                replaceDependencyVersion(asNode(), 'com.test', 'core', '1.+')
            }
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM