Apisero is now part of NTT DATA - Learn more.

Close this search box.

Publishing a Maven Artifact to GitHub Package Registry

Author: Sushma Kamuni

GitHub Packages is a platform for hosting and managing packages, including containers and other dependencies. GitHub Packages combines your source code and packages in one place to provide integrated permissions management and billing, so you can centralize your software development on GitHub.

Publishing a Maven artifact to GitHub Packages 

GitHub Package Repository provides an easy way to share dependencies like Maven artifacts between GitHub projects. Publishing of new artifacts into GitHub Package Repository can be automated with GitHub Actions.

  • Anypoint Platform Account
  • GitHub Repository Account
  • Git bash Terminal
  1. Adding distribution management in pom.xml 








  1. Commit the code to github

Steps to be followed


Download git bash on local system

  • Steps to commit the application
  1. Copy the github repository URL
  1. Create an empty folder in local directory and right-click on empty directory to open gitbash terminal.
  2. Enter the commands
    1. $ git clone <Copied URL from Git repository>

Downloads the data from the repository to the local directory

  1. $ cd <github repository name>

3. Now, in Anypoint Studio, right-click on the project -> Show In -> System Explorer. It redirects to the project folder in the workspace.

  1. Copy and paste the project files into the git local directory
  1. Next, in the terminal, enter commands 
    1. $ git add * (adds all the project files)
    2. $ git commit -m “Initial Commit” (Commits the files to set into git repository)
    3. $ git push (Pushes the files from local system to git repository)
  2. In the below screenshot, you can see that all the files are pushed to the git repository.
1.3. Personal Access Token for your GitHub account

To upload artifacts into the GitHub Package Registry, your Personal Access Token must have the scope – write:packages as shown below

1.4. Adding Personal Access Token and Github repo name in settings.xml





     <password>Your Personal Access Token</password>























Note: Locally, you can now publish a new Maven artifact into the GitHub Package Registry with the below command. 

$ mvn -Pgithub deploy

1.5. Publishing through GitHub Actions workflow 

name: Maven Package




      – main



    runs-on: ubuntu-latest


      – uses: actions/checkout@v2

      – name: Set up JDK 1.8

        uses: actions/setup-java@v1


          java-version: 1.8

          server-id: github

          server-username: GITHUB_USER_REF  # env variable name for username

          server-password: GITHUB_TOKEN_REF

      – name: Build with Maven.

        run: mvn clean package -DattachMuleSources -Pgithub deploy


          GITHUB_USER_REF: ${{ secrets.GIT_USERNAME }}

          GITHUB_TOKEN_REF: ${{ secrets.GIT_TOKEN }}

1.6. Creating secrets for GitHub username and token

 For creating secrets, goto Settings -> Secrets -> New Repository Secret button

With the next GitHub Actions build, your artifacts will be published in the repository’s dashboard

We can see the dependency created in packages

1.6. Installing a package

To install an Apache Maven package from GitHub Packages, edit the pom.xml file to include the package as a dependency.

  1. Authenticate to GitHub Packages.
  2. Add the package dependencies to the dependencies element of your project pom.xml file, replacing com.mycompany:hello-world-3 with your package.






  1. Install the package.

$ mvn install

Note:  Maven dependency downloaded at .m2\repository\com\mycompany\hello-world-3

2. Deploying the jar file to Runtime Manager
  1. Download the jar file from Github packages
  1. Copy the jar file and paste to the local repository.
  2. Open the gitbash terminal, clone the repository and follow below commands

$ git clone <url>

$ git pull

$ add <.jar file>

$git commit -m “<add comments>”

$git push 

 Provide github token as username and password in the pop up window

We can see in the below screenshot, a jar file is added to the repository.

2.1. Deploying jar file to Runtime Manager through Github actions

name: Deploying on to Runtime Manager



    branches: [ main ]


    branches: [ main ]



    # The type of runner that the job will run on

    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job


      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it

      – uses: actions/checkout@v2

      – name: Cache

        uses: actions/cache@v2.1.5


    # A list of files, directories, and wildcard patterns to cache and restore

          path: /home/runner/.m2/repository

          key: ${{ runner.os }}-maven-${{ hashFiles(‘**/pom.xml’) }}

          restore-keys: |

              ${{ runner.os }}-maven-

      – name: Setup Java JDK

        uses: actions/setup-java@v1


    # The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in the README file

          java-version: 1.8   

      – name: Deploy to CloudHub


          USERNAME: ${{ secrets.ANYPOINT_USERNAME }}

          PASSWORD: ${{ secrets.ANYPOINT_PASSWORD }}

        run: |

          artifactName=$(ls *.jar | head -1)

          mvn mule:deploy -Dmule.artifact=$artifactName -Danypoint.userName=$USERNAME -Danypoint.password=$PASSWORD -Danypoint.env=”Sandbox” -Danypoint.appName=”DEMO-WORK-1″

2.3. Adding the Maven plugin and cloudhub configuration in pom.xml



















Similarly we can download old version jar files and deploy to Runtime Manager.

The below screenshot shows the jar file is successfully deployed on Runtime Manager




We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.