Configuring Apache Maven for use with GitHub Packages

You can configure Apache Maven to publish packages to GitHub Packages and to use packages stored on GitHub Packages as dependencies in a Java project.

It solves to return the data type in micro service model when call the others services.

You can follow by steps:

* Build

– Step 1: Authenticating to GitHub Packages

You use a personal access token with the appropriate scopes to publish and install packages in GitHub Packages.

– Step 2: create new file or edit file (if it exist) setting.xml

Note: 

+ Ubuntu/Linux: vim ~/.m2/settings.xml

+ Win: path:Usersuser.m2setting.xml (c:UsersJVMD.m2settings.xml)

<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>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
        <repository>
          <id>yourPackage1</id>
          <name>GitHub OWNER Package1 Maven Packages</name>
          <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url>
        </repository>
      </repositories>
    </profile>
  </profiles>

  <servers>
    <server>
      <id>github</id>
      <username>your username in github</username>
      <password>your personal access token</password>
    </server>
  </servers>
</settings>

– Step 3: Publishing a package

In your project, edit pom.xml file.

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

– Step 4: deploy

mvn deploy

* Installing a package:

– Step 1: go to your project and edit pom.xlm file

<dependencies>
  <dependency>
    <groupId>com.example</groupId>
    <artifactId>test</artifactId>
  </dependency>
</dependencies>

– Step 2: run

mvn install

Reffer: https://docs.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-apache-maven-for-use-with-github-packages#authenticating-with-a-personal-access-token

Done. It’s simple.

Leave a Reply

Your email address will not be published. Required fields are marked *