Sitemap

Using GitHub package to host private artifacts(Jars)

2 min readOct 27, 2024

--

Press enter or click to view image in full size
Using GitHub package for managing artifacts in release pipeline
GitHub Packages in Release pipeline

Typically in a large enterprise, the private artifacts(enterprise jars) are managed by a dedicated artifact hosting service(like JFrog). The GitHub package is a good way to maintain artifacts associated with a project.

We already have an article about publishing your Java project into GitHub packages and using them as dependencies in another project.

I need to host a few enterprise jars privately so that they can be accessed in our release pipeline. I couldn’t find anything that guided me on this. So, I decided to write one.

Steps to get your artifact published:

  1. Create a GitHub repository that can hold the artifacts(Jars) as packages.
  2. Generate GitHub Personal Access Token (classic) to read and write packages.
  3. Update maven’s settings.xml to point maven to the GitHub account of the repository.
  4. Execute the maven deploy-file command to upload the artifact to the repository.
mvn deploy:deploy-file -Dfile=gson-2.11.0.jar -DpomFile=gson-2.11.0.pom -DrepositoryId=github -Durl=https://maven.pkg.github.com/sabarinathan590/github-package-sample -Dtoken=ghp_************************************

Explanation:

Get Sabarinathan Subramanian’s stories in your inbox

Join Medium for free to get updates from this writer.

mvn deploy:deploy-file — Maven deploy file plugin.

-Dfile — file that needs to be published to the GitHub package

-DpomFile — pom file corresponding to the jar file

-DrepositoryId — GitHub where we upload the file

-Durl — GitHub package repository URL. It should point to the repository where we need to upload the jar file

-Dtoken— GitHub Personal Access Token with write access to repository package.

Voila! The jar is uploaded to the GitHub package.

Press enter or click to view image in full size
Press enter or click to view image in full size

The repository where the jar is uploaded as a package.

Updating setttings.xml

The Maven settings.xml is typically located in the user’s home directory under the .m2 folder (/Users/sabarinathan/.m2). If it is not present, create one with the below content.

<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>

<servers>
<server>
<id>github</id>
<username>sabarinathan590</username>
<password>ghp_************************************</password>
</server>
</servers>
</settings>

--

--