By uploading it to GitHub's own package registry, you can easily use the relevant dependency in your project.
For applications written with Spring Boot + Maven, you can follow the steps below:
- To enable deployment of the project on GitHub, you should add the following code block to the
pom.xmlfile:
<distributionManagement>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/{username}/{repository-name}</url>
</repository>
</distributionManagement>
- Then, you need to create a new token from the
https://github.com/settings/tokensaddress. After that, you should add your information to thesettings.xmlfile and place it in the.m2folder.
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<activeProfiles>
<activeProfile>github</activeProfile>
</activeProfiles>
<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/{username}/{repository-name}</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>{username}</username>
<password>{your-personal-token}</password>
</server>
</servers>
</settings>
After completing the first two steps, the project should be present in a repository on GitHub. Therefore, you need to create a repository on GitHub for the project and then upload it there.
Once the project is available on GitHub, all you need to do is run the
mvn clean deploycommand in the directory where the project is located.
After this process is completed, you can access your project dependency through https://github.com/{username}/{Brepository-name}/packages. The relevant dependency example will already be available. You can add this dependency example to your project and use it like any other dependency.
<repositories>
<repository>
<id>{artifactId}</id>
<url>https://maven.pkg.github.com/{username}/{repository-name}</url>
</repository>
</repositories>
The important thing to remember is that only one dependency can be created for each version. If you want to create a new dependency for the same version, you need to delete the corresponding dependency on GitHub. After taking action on this, it would be very helpful if you share the outcome with me or provide feedback in case you encounter any issues.
Additionally, if you have your own solutions, you can share them under this post as well!