在 pom.xml 中覆盖用于上传的存储库
Posted
技术标签:
【中文标题】在 pom.xml 中覆盖用于上传的存储库【英文标题】:Override repository for upload in pom.xml 【发布时间】:2019-11-01 13:13:12 【问题描述】:背后的故事:我向 GitHub 中的某个公共 repo 提交了一个错误,它已被修复,但当我要求发布这些更改时,我没有得到任何回应。所以我正在等待下一个库版本 2 个月。所以我决定分叉这个 repo 并发布到自定义 Bintray。回购是https://github.com/okta/okta-sdk-java
项目有多个maven模块:
$ find . -type f -name pom.xml
./httpclients/okhttp/pom.xml
./httpclients/httpclient/pom.xml
./impl/pom.xml
./swagger-templates/pom.xml
./pom.xml
./integration-tests/pom.xml
./api/pom.xml
./coverage/pom.xml
./examples/pom.xml
./examples/quickstart/pom.xml
我只需要发布impl
模块。
问题是rootpom.xml
有父配置:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.okta</groupId>
<artifactId>okta-parent</artifactId>
<version>14</version>
<relativePath>../okta-java-parent</relativePath>
</parent>
<groupId>com.okta.sdk</groupId>
<artifactId>okta-sdk-root</artifactId>
<version>1.6.0-SNAPSHOT</version>
<packaging>pom</packaging>
所有部署配置都在okta-parent
pom.xml 中指定。
我试图用 (in root pom.xml
) 覆盖存储库配置:
<distributionManagement>
<repository>
<id>bintray-g4s8-maven</id>
<name>mvn</name>
<url>https://api.bintray.com/maven/g4s8/mvn/okta-sdk-impl/;publish=1</url>
</repository>
</distributionManagement>
但这没有帮助。
我在我的settings.xml
中有此 repo 的服务器配置,它适用于我的所有其他项目:
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>bintray-g4s8-maven</id>
<username>g4s8</username>
<password>...</password>
</server>
</servers>
</settings>
当我尝试发布它时出现错误:
$ mvn deploy -pl impl -Ppublish -DskipTests
...
[INFO] --- nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) @ okta-sdk-impl ---
[INFO] Performing deferred deploys (gathering into "/home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred")...
[INFO] Installing /home/projects/github.com/g4s8/okta-sdk-java/impl/target/okta-sdk-impl-1.6.0-SNAPSHOT.jar to /home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-SNAPSHOT.jar
[INFO] Installing /home/projects/github.com/g4s8/okta-sdk-java/impl/pom.xml to /home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-SNAPSHOT.pom
[INFO] Installing /home/projects/github.com/g4s8/okta-sdk-java/impl/target/okta-sdk-impl-1.6.0-SNAPSHOT-sources.jar to /home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-SNAPSHOT-sources.jar
[INFO] Installing /home/projects/github.com/g4s8/okta-sdk-java/impl/target/okta-sdk-impl-1.6.0-SNAPSHOT-javadoc.jar to /home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-SNAPSHOT-javadoc.jar
[INFO] Installing /home/projects/github.com/g4s8/okta-sdk-java/impl/target/okta-sdk-impl-1.6.0-SNAPSHOT-javadoc.jar to /home/projects/github.com/g4s8/okta-sdk-java/impl/target/nexus-staging/deferred/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-SNAPSHOT-javadoc.jar
[INFO] Deploying remotely...
[INFO] Bulk deploying locally gathered artifacts from directory:
[INFO] * Bulk deploying locally gathered snapshot artifacts
Downloading from sonatype-nexus-snapshots: https://oss.sonatype.org/content/repositories/snapshots/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/maven-metadata.xml
Downloaded from sonatype-nexus-snapshots: https://oss.sonatype.org/content/repositories/snapshots/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/maven-metadata.xml (993 B at 412 B/s)
Uploading to sonatype-nexus-snapshots: https://oss.sonatype.org/content/repositories/snapshots/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-20191101.130725-30-javadoc.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 58.070 s
[INFO] Finished at: 2019-11-01T16:07:41+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.8:deploy (injected-nexus-deploy) on project okta-sdk-impl: Failed to deploy artifacts: Could not transfer artifact com.okta.sdk:okta-sdk-impl:jar:javadoc:1.6.0-20191101.130725-30 from/to sonatype-nexus-snapshots (https://oss.sonatype.org/content/repositories/snapshots/): Failed to transfer file https://oss.sonatype.org/content/repositories/snapshots/com/okta/sdk/okta-sdk-impl/1.6.0-SNAPSHOT/okta-sdk-impl-1.6.0-20191101.130725-30-javadoc.jar with status code 401 -> [Help 1]
Maven 正在将工件上传到 https://oss.sonatype.org/
,而不是配置的 URL https://api.bintray.com/maven/g4s8/mvn/okta-sdk-impl/;publish=1
。如何强制它使用我的 URL 而不是父 URL?
更新
有效的 pom 在distributionManagement
中显示两个存储库:
<distributionManagement>
<repository>
<id>bintray-g4s8-maven</id>
<name>mvn</name>
<url>https://api.bintray.com/maven/g4s8/mvn/okta-sdk-impl/;publish=1</url>
</repository>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<name>Sonatype Nexus Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
【问题讨论】:
看看this类似的问题。 看有效的pom,你看到的是哪个分发管理? @JFMeier 我将来自distributionManagement
的回购添加到问题中
【参考方案1】:
看起来您正在构建一个 SNAPSHOT 版本。配置的<snapshotRepository>
为oss.sonatype...
。您只添加了用于构建发布版本的配置。
【讨论】:
以上是关于在 pom.xml 中覆盖用于上传的存储库的主要内容,如果未能解决你的问题,请参考以下文章
为啥 Gradle 不使用插件 pom.xml 中声明的 Maven 存储库?
Travis CI 不使用 pom.xml 中提供的额外 Maven 存储库