Gradle mavenDeployer重写工件版本命令行



我使用gradle将构建的工件上传到我们的存储库管理器(Nexus)
我使用以下命令行:

./gradlew --stacktrace --info uploadArchives -PnexusUsername=de -PnexusPassword=np

在build.gradle文件中,我有:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "${nexusUrl}/content/repositories/releases") {
                authentication(userName: nexusUsername, password: nexusPassword)
            }
        }
    }
}

如何从命令行覆盖默认版本?

我找到了一种快速的方法来支持它
在build.gradle中,我添加并更新了uploadArchives:

...
version = getVersion()
// Option to override Nexus version by setting env var CUSTOM_VERSION
def pomVersion = System.getenv("CUSTOM_VERSION") ?: version
...
...
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: "${nexusUrl}/content/repositories/releases") {
                authentication(userName: nexusUsername, password: nexusPassword)
            }
            pom.version = pomVersion
        }
    }
}

现在,我只需要在运行命令行之前设置CUSTOM_VERSION

我希望这能有所帮助。欢迎更多选择!

最新更新