I've built up a dependency in java. Nothing special, just some utility functionality. I can deploy it locally, and use it with no problem, but I'd like to deploy it to maven central. I set up my POM using GitHub, and I cannot seem to get it to deploy to my repository. I have the settings.xml file located in the .m2 directory and it is shown below.
I have GPG installed, and have a key generated with it as well.
My end goal is I want to build/deploy this with proper signatures/hashes/etc to eventually deploy to central.
Can anyone see what I've done wrong here? I feel like it's some minor detail, but I'm really not sure
OS: Mac OSX Maven Version: Tried 3.9.2 and 3.8.8 with the same result IDE: VS Code
I run men clean deploy, and get the following:
[INFO] --- deploy:2.8.2:deploy (default-deploy) @ MyArtifactName ---
Uploading to github: https://www.github.com/MyUserName/MyRepoName/io/github/MyUserName/MyArtifactName/1.0/MyArtifactName-1.0.jar
Uploading to github: https://www.github.com/MyUserName/MyRepoName/io/github/MyUserName/MyArtifactName/1.0/MyArtifactName-1.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.692 s
[INFO] Finished at: 2024-09-08T00:10:46-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project MyArtifactName: Failed to deploy artifacts: Could not transfer artifact io.github.MyUserName:MyArtifactName:jar:1.0 from/to github (https://www.github.com/MyUserName/MyRepoName): status code: 301, reason phrase: Moved Permanently (301) -> [Help 1]
[ERROR]
I have searched in many places, hit YouTube, google, etc looking for some result. I really think this has something to do with GitHub authentication, or maybe something in my settings file, but I'm not sure.
I have tried several different configuration with the POM file, and none seem to work. Again, if I deploy locally, or install locally, it's all fine. Everything works as expected.
MyUserName MyRepoName
<settings>
<servers>
<server>
<id>github</id>
<username>MyUserName</username>
<password>GITHUB_CLASSIC_TOKEN_GENERATED</password>
</server>
</servers>
<profiles>
<profile>
<id>github</id>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2</url>
</repository>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/MyUserName/MyRepoName</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
</settings>
My POM has this:
<?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>my.namespace.name</groupId>
<artifactId>MyArtifactName</artifactId>
<version>1.0</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Generic Description</description>
<url>http://www.github.com/MyUserName</url>
<licenses>
<license>
<name>The Apache License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
</license>
</licenses>
<developers>
<developer>
<name>My Name</name>
<email>my.email@gmail.com</email>
<organization>My Name</organization>
<organizationUrl>http://www.github.com/MyUserName</organizationUrl>
</developer>
</developers>
<scm>
<connection>scm:git:git://github.com/MyUserName/MyRepoName.git</connection>
<developerConnection>scm:git:ssh://github.com:MyUserName/MyUserName.git</developerConnection>
<url>http://github.com/MyUserName/MyRepoName/tree/main</url>
</scm>
<distributionManagement>
<snapshotRepository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://www.github.com/MyUserName/MyRepoName</url>
</snapshotRepository>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://www.github.com/MyUserName/MyRepoName</url>
</repository>
</distributionManagement>
<properties>
<!-- github server corresponds to entry in ~/.m2/settings.xml -->
<github.global.server>github</github.global.server>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<!-- JUnit -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.10.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Most of these are auto generated add ons -->
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- additions from SonaType articles -->
<!-- Distribution Management and Authentication -->
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.7</version>
<extensions>true</extensions>
<configuration>
<serverId>github</serverId>
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
<!-- Javadoc and Sources Attachments -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- GPG Signed Components -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Well, I did some more digging and found a manual way to do this.
I took the following steps:
compiled and installed my code:
man compile
mvn install
Generated my Javadoc:
mvn javadoc:jar
Generated my Sources:
mvn sources:jar
Then I had to sign all my files:
gpg -ab project-javadoc.jar
gpg -ab project-sources.jar
gpg -ab project.jar
gpg -ab project.pom
Then I had to create checksums:
md5 -r project-javadoc.jar > project-javadoc.jar.md5
md5 -r project-sources.jar > project-sources.jar.md5
md5 -r project.jar > project.jar.md5
md5 -r project.pom > project.pom.md5
shasum project-javadoc.jar > project-javadoc.jar.sha1
shasum project-sources.jar > project-sources.jar.sha1
shasum project.jar > project.jar.sha1
shasum project.pom > project.pom.sha1
Then I edited the generated files to remove the file names, and they just contained the sums.
Then I set up a project structure in the same design as my coordinates. IE - if you project is this:
<groupId>io.github.someUserName</groupId>
<artifactId>someProject</artifactId>
<version>1.0.1</version>
Your folder structure would be
io/github/someUserName/someProject/1.0.1/
Inside this folder, you place all your sources/signed files/etc
Zip it up.
Go to Sonatype, login to your account, upload your zip file.
Once validated, you can publish. Hours later, it'll be available once the repository updates.
Hope this helps someone along the way.