【问题标题】:Is there a way to reference maven settings.xml within gradle automatically?有没有办法在 gradle 中自动引用 maven settings.xml?
【发布时间】:2015-07-09 21:55:41
【问题描述】:

在我的 maven settings.xml 中,有如下几行:

<server>
  <id>releases</id>
  <username>myname</username>
  <password>mypassword</password>
</server>

另外,在 maven 构建中定义:

<distributionManagement>
  <repository>
    <uniqueVersion>true</uniqueVersion>
    <name>Local repo on Banana</name>
    <id>releases</id>
    <url>http://banana.com:8081/nexus/content/repositories/releases</url>
    <layout>default</layout>
  </repository>
</distributionManagement>

在 gradle 中,您可以通过以下方式定义存储库引用:

repositories {
    mavenDeployer {
        repository (url: "http://banana.com:8081/nexus/content/repositories/releases", id: "releases"){
            //...filler...
        }
    }
}

问题是,gradle 可以引用系统上的主要 settings.xml 文件吗?
(因此会自动提取与存储库 id 匹配的凭据,就像 maven 一样)

到目前为止,我能找到提供身份验证凭据的唯一方法是在 gradle.build 中明确列出它们......就像这样:

repositories {
    mavenDeployer {
        repository (url: "http://banana.com:8081/nexus/content/repositories/releases", id: "releases"){
            authentication(userName: "billybob", password: "bananas?!")
        }
    }
}

我目前的计划是引用环境变量,但我希望有一种方法可以引用现有的 settings.xml 定义。

【问题讨论】:

标签: maven gradle


【解决方案1】:

将以下行添加到 gradle.properties 文件中:

repoUser=user123
repoPassword=123abc

然后在你的 build.gradle 中添加以下内容:

repositories {
maven {
    credentials {
        username repoUser
        password repoPassword
    }
    url "http://nexus........."
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2022-01-13
    • 1970-01-01
    • 2023-03-31
    • 2017-02-15
    • 1970-01-01
    • 2021-04-06
    相关资源
    最近更新 更多