Installing a private GitHub maven package in CircleCI?

My Maven web application uses several JAR dependencies hosted as private GitHub packages. I’m trying to set up a CI/CD pipeline with CircleCI.

When CircleCI tries to build with mvn package, it fails with a 401 when attempting to install the private packages. I don’t know how to approach authenticating. I’ve added SSH deploy and user keys to the project settings, but that doesn’t seem to help Maven. I know that locally, I added a server tag with my personal access token to the .m2/conf/settings.xml file to authenticate. But what should I do within CircleCI? Googling hasn’t revealed anything.

Update: I included settings.xml with a hardcoded access token within the repository and included -gs ./settings.xml in my maven build command to point to it. Works but doubt this is best practice, so leaving the question open.

You can reference environment variables in your settings.xml. It’s best to keep the secrets in environment variables configured within the project settings. Then use the technique in this stackoverflow to access the values from the environment without having to commit them to your repo.

<servers>
    <server>
      <id>deploymentRepo</id>
      <username>${env.SERVER_USERNAME}</username>
      <password>${env.SERVER_PASSWORD}</password>
    </server>
</servers>

In the example above SERVER_USERNAME and SERVER_PASSOWORD are accessed through envars.

You should delete and create a new personal access token, and then save the new one as a project envar to be used by your settings file.

Hi, thanks for the response. But how would I access the environment vars within CircleCI’s container? Wouldn’t that only work locally?

EDIT: Using Environment Variables - CircleCI Seems this is what I’m looking for.

1 Like