gpt4 book ai didi

gradle - 我可以向 gradle.properties 添加自定义存储库吗?

转载 作者:行者123 更新时间:2023-12-03 04:47:40 24 4
gpt4 key购买 nike

我希望能够在设置中定义一个存储库(最好是用户 gradle.properties)

最终目标是这样的:

repositories {
mavenCentral() // Can't/don't want to use this
nexusCentral() // Can use these - on network Nexus server
nexusSnapshot()
}

我该怎么做呢?同样,理想情况下,这将放在用户级 gradle.properties 文件中,因此我们不必在每个模块中都引用它。

这只是 Maven 提供的一个普通的 Maven 风格的工件存储库,手动方式是:
maven {
url "http://path/to/nexus"
}

另一个要求是使用“发布”任务,该任务具有为存储库定义的凭据(Jenkins 用于发布模块):
publishing {
...
maven {
url "http://path/to/nexus"
// Jenkins provides these as -P Gradle parameters.
credentials {
username = "${uploaderUser}"
password = "${uploaderPassword}"
}
}

这些凭据不会被普通用户知道,但理想情况下会在 Jenkins 的 gradle.properties 中配置。我们不希望用户构建失败,因为他们无法解析凭据 - 他们甚至不会使用“发布”任务。

最佳答案

你可以使用这样的东西:

   maven {
credentials {
username getCredentialsMavenUsername()
password getCredentialsMavenPassword()
}
url 'xxxxx'
}

/**
* Returns the credential username used by Maven repository
* Set this value in your ~/.gradle/gradle.properties with CREDENTIALS_USERNAME key
* @return
*/
def getCredentialsMavenUsername() {
return hasProperty('CREDENTIALS_USERNAME') ? CREDENTIALS_USERNAME : ""
}

/**
* Returns the credential password used by Maven repository
* Set this value in your ~/.gradle/gradle.properties with CREDENTIALS_PASSWORD key
* @return
*/
def getCredentialsMavenPassword() {
return hasProperty('CREDENTIALS_PASSWORD') ? CREDENTIALS_PASSWORD : ""
}

如果用户没有凭据,则脚本不会失败。

关于gradle - 我可以向 gradle.properties 添加自定义存储库吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35876158/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com