How do I set up my Java/Maven project to publish packages to GitHub Packages?

I’ve created a java library project on github (GitHub - blackears/java-psd-library: Mirror of the java-psd-library with Maven definition.) and am trying to figure out how to publish it as a github package so that it can be included as a resource in a maven file.

I’m trying to follow the directions here, but am finding them vague:

Right now, I have my pom file set up to build binary, source and javadoc jar files. I’m not sure what to do next. What steps do I need to take to publish them as packages on GitHub Packages?

1 Like

Here are my expiriences:

  • Set up a GitHub workflow for deploying, to GitHub Packages (GHPM)
name: Publish package to GitHub Packages
on:
  release:
    types: [published]
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v1
        with:
          java-version: 14
      - name: Publish package
        run: mvn --batch-mode deploy
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  • Configure your pom.xml
    <distributionManagement>
        <repository>
            <id>github</id>
            <name>GitHub Packages</name>
            <url>https://maven.pkg.github.com/[[OWNER]]/[[REPO]]</url>
        </repository>
    </distributionManagement>
  • Make sure you replace [[]OWNER] with your GitHub user name
  • Make sure you replace [[REPO]] with your Repository name

Now every time you publish a new release, the release will automaticly deploy on GHPM