Last active
December 5, 2019 21:20
-
-
Save Mattamorphic/4a86fff7eeeb345aa191b154366f3d3a to your computer and use it in GitHub Desktop.
Example Maven Configuration : Installing a package
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.mattamorphic.maven.gpr</groupId> | |
<artifactId>maven-install-test</artifactId> | |
<version>1.0.0</version> | |
<dependencies> | |
<dependency> | |
<groupId>com.mattamorphic</groupId> | |
<artifactId>maven-assembly-example</artifactId> | |
<version>0.2</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project xmlns="http://maven.apache.org/POM/4.0.0" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | |
http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.mattamorphic</groupId> | |
<artifactId>maven-assembly-example</artifactId> | |
<version>0.2</version> | |
<properties> | |
<maven.compiler.source>1.8</maven.compiler.source> | |
<maven.compiler.target>1.8</maven.compiler.target> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.apache.commons</groupId> | |
<artifactId>commons-lang3</artifactId> | |
<version>3.0</version> | |
</dependency> | |
</dependencies> | |
<distributionManagement> | |
<repository> | |
<id>github</id> | |
<name>GitHub mattamorphic Apache Maven Packages</name> | |
<url>https://maven.pkg.github.com/mattamorphic/maven-assembly-example/</url> | |
</repository> | |
</distributionManagement> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<configuration> | |
<source>7</source> | |
<target>7</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-jar-plugin</artifactId> | |
<version>2.4</version> | |
<configuration> | |
<archive> | |
<manifest> | |
<addClasspath>true</addClasspath> | |
<classpathPrefix>lib</classpathPrefix> | |
<mainClass>com.sample.Main</mainClass> | |
</manifest> | |
</archive> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-assembly-plugin</artifactId> | |
<executions> | |
<execution> | |
<phase>package</phase> | |
<goals> | |
<goal>single</goal> | |
</goals> | |
<configuration> | |
<appendAssemblyId>false</appendAssemblyId> | |
<descriptors> | |
<descriptor>src/com/assembly/zip.xml</descriptor> | |
</descriptors> | |
</configuration> | |
</execution> | |
</executions> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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>github</id> | |
<name>GitHub mattamorphic Apache Maven Packages</name> | |
<url>https://maven.pkg.github.com/mattamorphic/maven-assembly-example</url> | |
</repository> | |
<repository> | |
<id>github</id> | |
<name>GitHub mattamorphic Apache Maven Packages</name> | |
<url>https://maven.pkg.github.com/mattamorphic/test-service</url> | |
</repository> | |
</repositories> | |
</profile> | |
</profiles> | |
<servers> | |
<server> | |
<id>github</id> | |
<username>mattamorphic</username> | |
<password>TOKEN</password> | |
</server> | |
</servers> | |
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Maven package using Actions | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- 'mypackage/*' | |
- '.github/workflows/workflow.yml' | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v1 | |
- name: Setup Java | |
uses: actions/setup-java@v1 | |
with: | |
java-version: '9.0.4' | |
- name: Add GPR token to template settings.xml | |
run: sed -i -e 's/TOKEN/'$GITHUB_TOKEN'/g' mypackage/settings.xml | |
env: | |
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | |
- name: Create the package | |
run: | | |
cd mypackage/ | |
mvn package --settings settings.xml | |
- name: Publish the package | |
run: | | |
cd mypackage/ | |
mvn deploy --settings settings.xml |
fully agree with harmanpa.. We have 90+ maven repositories hosted on Github in our organization. we've abandoned migrating to Github Package Registry for this reason alone.. We are definitely not going to update the settings.xml for all developers for 90+ repositories and having to update it every time we have a new repository. The repositories should be hosted at the organization level.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If the Maven repository was hosted at
https://maven.pkg.github.com/<username>
rather thanhttps://maven.pkg.github.com/<username>/<repo>
it would be much more practical for users with a large number of libraries, else we will end up having to list a huge number of Maven repositories - and Maven checks every single one until it finds a package.