This guide will walk you through the process of getting and accessing Maven GitHub Packages using a personal access token. You can either integrate the token directly into your pom.xml (potentially unsafe) or set it up in your ~/.m2/settings.xml (safe)
- Navigate to Settings>Developer Settings>Personal access tokens>Tokens (classic)>Generate new token (classic)
- Check the
read:packages
option (Download packages from GitHub Package Registry). - Click on
Generate token
at the bottom. - Make sure to copy the generated token for later use.
- Visit: https://github.com/REPOOWNER/REPONAME/packages.
- Select the package you want to use.
- Copy and paste the dependency into your project.
You have two options:
pom.xml
and when uploading your project somewhere your access token is exposed to anyone who has access to that page.
Import the Repository:
<repositories>
<repository>
<id>github-REPONAME</id>
<name>GitHub PACKAGENAME Apache Maven Package</name>
<url>https://YOUR_GITHUB_NAME:[email protected]/REPOOWNER/REPONAME</url>
</repository>
</repositories>
Note: Replace placeholders (in uppercase) with actual values.
-
Locate the
~.m2
folder.- Windows:
%USERNAME%\.m2
(paste this into the explorer's address bar)
- Windows:
-
Create the
settings.xml
. -
Paste the following:
<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>github-REPONAME</id>
<name>GitHub PACKAGENAME Apache Maven Package</name>
<url>https://YOUR_GITHUB_NAME:[email protected]/REPOOWNER/REPONAME</url>
<!-- You may want to turn this on -->
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>YOUR_GITHUB_NAME</username>
<password>ACCESS_TOKEN</password>
</server>
</servers>
</settings>
Note: Replace placeholders (in uppercase) with actual values.