【发布时间】:2020-02-14 17:08:00
【问题描述】:
我将一个 maven artefact 上传到 GitHub Package Registry (Beta) 并希望将其添加为 maven 依赖项。我已经在Regestry-Beta 中并为我的示例HalloMaven 项目激活了它。 mvn deploy 也成功了,所以工件是 public 在此处可用:
https://github.com/TobseF/HelloMaven/packages
但是如何将其包含为 maven 依赖项?
我尝试使用 pom.xml 将其添加到一个新的示例项目中:
<groupId>de.tfr.test</groupId>
<artifactId>maven-repo-test</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>github</id>
<name>GitHub TobseF Apache Maven Packages</name>
<url>https://github.com/TobseF/HelloMaven/packages</url>
<!-- also tried:
<url>https://maven.pkg.github.com/HelloMaven/</url> -->
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>github.tobsef</groupId>
<artifactId>hello-maven</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
但是无法解决依赖关系。
奇怪的是artifactId是github.tobsef.hello-maven,和pom中指定的hello-maven不匹配。但我不知道为什么 github.tobsef 会在前面加上存储库 url 是否正确。
官方 GitHub Configuring Apache Maven for use with GitHub Package Registry 仅显示如何使用凭据推送。但我的仓库是公开的,不需要身份验证。
HalloMaven 示例的设置:
settings.xml
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>github</id>
<name>GitHub TobseF Apache Maven Packages</name>
<url>https://maven.pkg.github.com/TobseF</url>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>${env.GITHUB_USERNAME}</username>
<password>${env.GITHUB_TOKEN}</password>
</server>
</servers>
pom.xml
<groupId>github.tobsef</groupId>
<artifactId>hello-maven</artifactId>
<version>1.2.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
</plugins>
</build>
<properties>
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub TobseF Apache Maven Packages</name>
<url>https://maven.pkg.github.com/TobseF/HelloMaven</url>
</repository>
</distributionManagement>
deploy.yml
name: Maven Deploy
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Maven build
run: mvn --file pom.xml package
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Deploy to Github Package Registry
env:
GITHUB_USERNAME: ${{ secrets.GITHUB_USERNAME }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: mvn --settings settings.xml --file pom.xml deploy
结果是Could not find artifact github.tobsef:hello-maven:pom:1.2.1 in github (https://github.com/TobseF/HelloMaven/packages)。
任何想法如何设置部署以部署正确的工件以及如何将其添加为依赖项?
【问题讨论】:
-
您的作品可以通过搜索找到:github.com/… - 到目前为止一切顺利。它显示的工件是:`
` 这是与您似乎使用的不同的 artifactId。似乎settings.xml repo url是正确的,你在pom中使用的那个与你链接的文档不匹配。com.github.tobsef github.tobsef.hello-maven 1.2.1 -
> 这是与您似乎使用的不同的 artifactId。是的,但是当我尝试添加这个 artifactId 时,我也不起作用。 > 你在 pom 中使用的他与文档不匹配我在示例项目中使用的依赖
artifactId,与部署的工件路径匹配。只有部署的 jar 中的artifactId不匹配 - 这不应该阻止它下载? -
github.com/TobseF/HelloMaven/packages/39042 中列出的 artifactId 现在匹配。没有任何改变......可能在 GitHubs 方面出现错误(Beta 产品)。那么现在唯一的问题是如何将其包含为依赖项?
-
好吧,这些存储库无法以某种方式浏览。所以尝试和错误。你确定它是一个公共回购吗?后面:maven.pkg.github.com/TobseF/github/tobsef 我收到需要登录的 401 错误。像maven.pkg.github.com/TobseF/github/tobsef/hello-maven/1.2.2/… 这样的东西应该是正确的。但是需要身份验证,无法检查。
-
您是否尝试过使用
publishToMavenLocal命令在本地测试您的部署?