Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Copilot Lvl 2
Message 1 of 3

GitHub Package Registry Maven Deploy

Hi,

 

so I'm trying to deploy a simple java maven project to GitHub Package Registry. I followed the steps in https://help.github.com/en/github/managing-packages-with-github-packages/configuring-apache-maven-fo... but I can't get things working.

First I was getting 401 and I guess that was a token problem. I've generated a new one as explained in the site and that error is gone. Now my current status is

settings.xml

<profile>
	<id>github</id>
	<repositories>
		<repository>
			<id>central</id>
			<url>https://repo1.maven.org/maven2</url>
			<releases><enabled>true</enabled></releases>
			<snapshots><enabled>false</enabled></snapshots>
		</repository>
		<repository>
			<id>github</id>
			<name>GitHub tvcsantos Apache Maven Packages</name>
			<url>https://maven.pkg.github.com/tvcsantos/releases</url>
		</repository>
	</repositories>
</profile>


I also have the server with the username as tvcsantos and the password is the token that i've generated.

 

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>pt.com.santos</groupId>
    <artifactId>java-util</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <name>JavaUtils</name>
    
    <scm>
        <url>https://maven.pkg.github.com/tvcsantos/releases</url>
    </scm>
    
    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub tvcsantos Apache Maven Packages</name>
            <url>https://maven.pkg.github.com/tvcsantos/releases</url>
        </repository>
    </distributionManagement>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

 

after a mvn deploy I've the following output:

[INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ java-util ---
Uploading to github: https://maven.pkg.github.com/tvcsantos/releases/pt/com/santos/java-util/1.0/java-util-1.0.jar
Uploading to github: https://maven.pkg.github.com/tvcsantos/releases/pt/com/santos/java-util/1.0/java-util-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.851 s
[INFO] Finished at: 2020-01-03T23:41:26Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project java-util: Failed to deploy artifacts: Could not find artifact pt.com.santos:java-util:jar:1.0 in github (https://maven.pkg.github.com/tvcsantos/releases) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException


Can someone explain what is going on

 

Thanks

 

2 Replies
Highlighted
Ground Controller Lvl 1
Message 2 of 3

Re: GitHub Package Registry Maven Deploy

I posted my solution to a similar problem here: https://stackoverflow.com/a/60333215/1483911

Highlighted
Ground Controller Lvl 1
Message 3 of 3

Re: GitHub Package Registry Maven Deploy

Also posted in StackOverflow.

 

The following solution works for me:

1. Create a repository for packages e.g. `maven-packages`

2. Add `<server></server>` settings under `<servers>` in `settings.xml`: (do this per id used below)

    <server>
        <id>github<id/>
        <username>YOUR GITHUB USERNAME</username>
        <password>A GITHUB TOKEN YOU CREATE FOR PUBLISHING PACKAGES</password>
    </server>

3. Do NOT add `<activeProfiles>`, `<profile>` or `<repositories>` to `settings.xml` (only add `<server>` elements) as this is redundant for publishing and I am adding them to consuming projects' `maven.xml` so no need for duplication.

4. Add repository/ies to `distributionManagement` in `pom.xml` as follows:

    <distributionManagement>
        <snapshotRepository>
            <id>github-snapshot</id>
            <name>GitHub snapshot</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>true</uniqueVersion>
        </snapshotRepository>
        <repository>
            <id>github-release</id>
            <name>GitHub release</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
            <uniqueVersion>false</uniqueVersion>
        </repository>
    </distributionManagement>

Where `OWNER` is the GitHub account your project is / projects are under and `maven-packages` is the repositories you want to publish you project(s) to. This enables using a dedicated repository for listing packages instead of publishing each project's package to a different (its own) repository, making consumption of multiple packages from your GitHub account easier, as you only need to configure a single repository for these packages:

    <repositories>
        <repository>
            <id>github</id>
            <name>GitHub</name>
            <url>https://maven.pkg.github.com/OWNER/maven-packages/</url>
        </repository>
    </repositories>

Note: in the `<servers>` section of your `settings.xml` define a `<server>` per `id` used in `repositories` and `distributionManagement` e.g. `github-snapshot`, `github-release`, `github` in the above examples.