如何在 gradle.settings 的插件管理块中添加私有存储库?



我正在尝试设置一个 gradle 5 项目,该项目使用某人开发的自定义插件,并在我公司内部存储库中可用。

到目前为止,我们一直使用以下方法导入它:

buildscript {
ext {
usr = System.env.usr != null ? System.env.usr : project.ext.properties.usr
pass = System.env.pass != null ? System.env.pass : project.ext.properties.pass
privateRepo = {
name "privateRepo"
url <url>
credentials {
username usr
password pass
}
}
}
repositories {
maven (privateRepo)
}
dependencies {
// various dependencies
classpath "org.something:some-plugin:1.0"
...
}
apply plugin: "someplugin"

就像这个问题一样。 据我了解,这是一种不推荐使用的方法,因此我想使用pluginManagement块gradle.settings(再次,如本答案所示)

问题是我的存储库是私有的,所以我需要定义用户并传递变量。

我在 gradle.settings 的pluginManagement块中尝试了类似的方法,但我无法让它工作:pluginManagement不支持ext块,pluginManagement必须是脚本中的第一个块,限制了我的替代方案。

无论如何,我可以定义变量以便它可以在pluginManagement块中使用吗?

免责声明:我的问题不是链接问题的副本,因为我的问题与凭据部分有关,我在定义变量和值时遇到问题。

好吧,我只是在块中添加了def,不理想,但至少可以工作:

pluginManagement {
def artifactoryUrl = "www.my.artifactory.url"
def artifactoryUser= "myUser"
def artifactoryPass= "myPass"
repositories {
maven {
name = "A-MavenGoogle"
url = uri(
"https://$artifactoryUrl/list/maven-google-remote/"
)
credentials {
username = artifactoryUser
password = artifactoryPass
}
}
maven {
name = "A-MavenCentral"
url = uri(
"https://$artifactoryUrl/list/maven-central-remote/"
)
credentials {
username = artifactoryUser
password = artifactoryPass
}
}
}
}

最新更新