Github Maven Repositories
Overview
- Generate Github Access Token
- Modify
~/.m2/settings.xml
to include Access Token & Repository - Modify
~/dev/MY-MAVEN-PROJECT/pom.xml
to include distribution management - Deploying and Viewing Maven Dependency
Part 1
Generate Github Access Token
- Navigate to
https://github.com/settings/tokens/new
] to generate a new token - Provide the
Note
field with a brief mnemonic of the purpose of the token; perhapsgithub-packages
- Provide the token with privielges of
repo
andwrite:packages
- Generate the new token and copy it somewhere safe
Part 2
Modify ~/.m2/settings.xml
to include Access Token & Repository
- Execute the command below to modify your maven settings file
nano ~/.m2/settings.xml
Note for Heroku Deployment:
include a copy of ~/.m2/settings.xml
in the root directory of a maven project upon deploying to Heroku.
Include settings
children: activeProfiles
, profiles
, and servers
- Replace
USERNAME
with your github username - Replace
TOKEN
with the newly generated access token fromPart 1
.
<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 https://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/*</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<servers>
<server>
<id>github</id>
<username>USERNAME</username>
<password>TOKEN</password>
</server>
</servers>
</settings>
Part 3
Deploying Maven Package
- Execute the command below to modify your
pom.xml
file - Replace
MY-MAVEN-PROJECT
with the respective project name.nano ~/dev/MY-MAVEN-PROJECT/pom.xml
- Create a
distributionManagement
tag as a child ofproject
- Replace
USERNAME
with the respective username - Replace
REPOSITORY
with the respective repository
- Replace
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub USERNAME Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</distributionManagement>
Part 4
Viewing Maven Package
- Execute the command below from the root directory of the maven project to deploy the package
mvn deploy -Dmaven.test.skip=true
- Navigate to the link below to view your newly deployed package; Replace
USERNAME
with the respective username