Christian Screen
Christian Screen

Build a Github Package on a Mac : .m2/settings.xml on a Mac

Twitter
LinkedIn

So much code is available as open source and our friends at github have given us mere mortal developers the ability to harness code packages as a way of building code bases on-demand when cloning other projects for a smaller overall footprint. In using Java Maven dependencies the consumer of the github repository will need a maven, obviously, but also to update the Maven settings file on their local machine. To do this Github has provided a fairly long-winded document, https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-apache-maven-registry to build a github package on a mac by modifying or creating the .md2/settings.xml file on a mac os.

Use a terminal or a finder capable of viewing hidden files and navigate to the ~/.m2/ directory. A simple preview of this using the following terminal command should pose no problem to make sure you are in the right place.

ls -lah ~/.m2

This is technically the same thing as accessing the /Users/<username>/.m2 directory, but your mileage may vary.

If you do not see the settings.xml file you will need to create it and typically an the following information after you have received your PERSONAL TOKEN from your Github developer settings,

<servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>

You can find or create your personal access token by clicking on your Profile > Settings > Developer Settings (left bottom of settings page)

Once you click on Developer settings you will need to create a “Personal access token” so click that option and typically you will choose the “(classic)” option. We’ve found that most integrations still us this classic option thought at the time of this writing the newer fined grained token is still in beta.

For packages you can check usually the READ option unless you need to create and store thus write a package back to Github. Most cloned repositories require you to only read, so usually selecting on that option is sufficient.

Add the token and your username to your existing settings.xml file. If you do not have an existing settings.xml file create one using the following structure:

<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
                      http://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/OWNER/REPOSITORY</url>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>USERNAME</username>
      <password>TOKEN</password>
    </server>
  </servers>
</settings>

Run the appropriate maven build commands and tweak as needed.

More to explorer

AI ChatGPT

Building a Generative AI Competency (or the First Gen AI Project)

When Building a Generative AI Competency one must identify the necessary infrastructure, architecture, platform, and other resources and partners that can help an AI initiative be successful. We have just like many data warehouse and digital transformation initiatives over the last 20 years fail because of poor leadership, or companies only going half in on the objective.

Scroll to Top