- check the maven setting file
mvn --version
mvn help:effective-settings
If not exist create your own from https://maven.apache.org/settings.html
-
Update Maven
setting.xml
from GitHub dochttps://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry
-
Create a token (required)
For the New personal access token
Add the newly generated token in your Maven setting.xml file
- Update the
pom.xml
file located in the project.
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
</repository>
</distributionManagement>
- Add packaging to package the library
<packaging>jar</packaging>
- Add Maven plugin compiler to compile the code
TBD
This step auto-deploys the package once the code change is pushed/merged
- create new folders
.github/workflows
- Create
publish-java-maven.yml
- Required new secret used your token
name: Publish package to GitHub Packages
on: push
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
distribution: 'adopt'
- name: Publish package
run: mvn --batch-mode deploy
env:
GITHUB_TOKEN: ${{ secrets.JAVA_TOKEN }}