I uploaded a maven artefact to the GitHub Package Registry (Beta) and want to add it as maven dependency. I'm already in the Regestry-Beta and activated it for my sample HalloMaven project. Also the mvn deploy
was succesful, so the artifact is public available here:
https://github.com/TobseF/HelloMaven/packages
But how to include it as a maven dependency?
I tried to add it in a fresh sample project with this 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>
But the dependency cannot be resolved.
It's strange that the artifactId
is github.tobsef.hello-maven
, which doesn't match the hello-maven
specified in the pom. But I have no clue why the github.tobsef
gets prepended and if the repository url is correct.
The official GitHub Configuring Apache Maven for use with GitHub Package Registry only shows how to push it with credentials. But my repo is public, authentication is not needed.
Setup for the HalloMaven example:
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
The result is a Could not find artifact github.tobsef:hello-maven:pom:1.2.1 in github (https://github.com/TobseF/HelloMaven/packages)
.
Any Idea how to setup the deployment to deploy the correct artifact and how to add it as dependency?
artifactId
I used in the sample project, match with the deployed artifact path. Only theartifactId
inside the deployed jar doesn't match - which shouldn't prevent it from downloading? – ShrapnelpublishToMavenLocal
command? – Breslau