Optimized configuration for the repository

Please I would like to ask some help, probably someone already had this problem:
If I use this, for the settings.xml config:

<repository>
    <id>github</id>
    <name>GitHub OWNER Apache Maven Packages</name>
    <url>https://maven.pkg.github.com/OWNER</url>
</repository>

and to publish a package:

<distributionManagement>
   <repository>
     <id>github</id>
     <name>GitHub OWNER Apache Maven Packages</name>
     <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
   </repository>
</distributionManagement>

this is good that the packages got uploaded correctly and I can see under each repository the packages published.
But to resolve the package, it requires to add the package before the group-id:

<dependency>
     <groupId>REPOSITORY.GROUP-ID</groupId>
     <artifactId>ARTIFACT-ID</artifactId>
</dependency>

Or to my setting.xml requires one repository tag to each library we have in the company.
Too much configuration.

Is there a better way to do that? or I can’t use the publish packages under each repository and use just the OWNER level?

Or to my setting.xml requires one repository tag to each library we have in the company.
Too much configuration.

There is a way to avoid adding multiple server elements to an external settings.xml file.

You can define repository entries in your pom.xml file like this (they must have unique ids):

    <repository>
      <id>maven-example</id>
      <name>GitHub actions-packages-examples Apache Maven Packages</name>
      <url>https://token:${token}@maven.pkg.github.com/actions-packages-examples/maven-example</url>
    </repository>

You can then pass the token to Maven:

mvn compile -Dtoken=<READ_PACKAGES_TOKEN>

<READ_PACKAGES_TOKEN> is a PAT with the read:packages scope.

I hope that helps!

What I would like to avoid is multiple repository entries in the settings.xml. One to each github repository. Like suggested on the documentation:

If you want to interact with multiple repositories, you can add each repository to separate repository children in the repositories tag, mapping the id of each to the credentials in the servers tag.

Yes, we need to publish and work with several libraries each of then from a different repository in Github. But I don’t want to add one extra repository entry to the settings, every time we add a new library.
I also test and does not work to deploy/publish a package in the level of the organization: https://maven.pkg.github.com/OWNER only with the repository: https://maven.pkg.github.com/OWNER/REPOSITORY.

So maybe the last alternative so far is to publish all the libraries to one GitHub repository then use it in the settings.xml, so all the projects will be able to resolve the library using the basic:

<dependency>
     <groupId>GROUP-ID</groupId>
     <artifactId>ARTIFACT-ID</artifactId>
</dependency>

What I would like to avoid is multiple repository entries in the settings.xml . One to each github repository.

What I prefer to do is put the repository entries in my pom.xml rather than my settings.xml.

For example:

The settings.xml then only needs to contain server entries:

I’ve created and XML encoded a PAT with just the read:packages scope so that it can be pushed to a public repository without being deleted when GitHub detects a PAT.

If you have Docker installed, you can XML encode a token like this:

docker run jcansdale/gpr xmlEncode TOKEN

(the source is here https://github.com/jcansdale/gpr/blob/623047bce1ffec6074c13197ecc3f32c5148a240/src/GprTool/Program.cs#L452)

I’ve also created a .mvn/maven.config to automatically use my local settings.xml file. See:

This means I can do the following without any extra ceremony!

git clone https://github.com/jcansdale-test/maven-consume
cd maven-consume
mvn compile

I hope that helps.

1 Like