Skip to content

Instantly share code, notes, and snippets.

@mcgivrer
Last active February 4, 2022 10:45
Show Gist options
  • Save mcgivrer/5288a7a4ba55a48412b8db81d3e0c93f to your computer and use it in GitHub Desktop.
Save mcgivrer/5288a7a4ba55a48412b8db81d3e0c93f to your computer and use it in GitHub Desktop.
Maven POM with packaging, producing an archive containing the a jar and some launching scripts

README

The structure of this project template is as follow:

[projectRoot]
|_ src
|  |_ assembly
|  |  |_scripts
|  |  |_dep.xml
|  |_ main
|  |  |_ docs
|  |  |_ java
|  |  |_ resources
|  |_ site
|  |_test
|_ README.md
|_ pom.xml

where dep.xml is the assembly packaging rules to be executed at the package maven goal.

Just execute :

mvn package

You will get a package in the target build area, havinhg a [projectname]-[version]-bin.zip and a [projectname]-[version]-bin.tar.gz file. The list of possible archive type can be found at Apache Maven Assembly Plugin page.

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>bin</id>
<formats>
<format>tar.gz</format>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>README*</include>
<include>LICENSE*</include>
<include>NOTICE*</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/bin</outputDirectory>
<includes>
<include>*-shaded.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}/site</directory>
<outputDirectory>docs</outputDirectory>
</fileSet>
</fileSets>
<files>
<file>
<outputDirectory>/</outputDirectory>
<source>src/assembly/scripts/launch.sh</source>
<filtered>true</filtered>
</file>
<file>
<outputDirectory>/</outputDirectory>
<source>src/assembly/scripts/launch.bat</source>
<filtered>true</filtered>
</file>
</files>
</assembly>
<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>fr.snapgames.core</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo</name>
<description>A demonstration project on how to create sustainable project.</description>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.mainClass>fr.snapgames.demo.Demo</project.mainClass>
</properties>
<!-- Project Dependencies -->
<dependencies>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.33</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.33</version>
</dependency>
<!-- tests things -->
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>7.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.2.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
<!-- Compilation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<!-- Resource copying -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<!-- Compute coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Sources -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Javadoc -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<encoding>utf-8</encoding>
<stylesheet>maven</stylesheet>
<source>1.8</source>
<show>public</show>
<failOnError>false</failOnError>
<failOnWarnings>false</failOnWarnings>
<useStandardDocletOptions>false</useStandardDocletOptions>
<linksource>false</linksource>
<show>private</show>
<nohelp>true</nohelp>
<overview>${project.basedir}/README.md</overview>
<bottom>
<![CDATA[<em>Copyright © \\${project.inceptionYear} - SnapGames.</em>]]>
</bottom>
<!-- more links than can (or not) be added -->
<!--links>
<link>${project.issueManagement.url}</link>
<link>${project.ciManagement.url}</link>
<link>https://docs.oracle.com/en/java/javase/11/docs/api/</link>
</links-->
<!--doclet>ch.raffael.mddoclet.MarkdownDoclet</doclet>
<docletArtifact>
<groupId>ch.raffael.markdown-doclet</groupId>
<artifactId>markdown-doclet</artifactId>
<version>1.4</version>
</docletArtifact-->
<useStandardDocletOptions>true</useStandardDocletOptions>
</configuration>
<executions>
<execution>
<id>attach-javadocs</id>
<phase>verify</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Build the minimalist JAR without dependencies (Normal Edition) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>${project.mainClass}</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- Shaded jar with all dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<!-- put your configurations here -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${project.mainClass}</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>src/main/resources/</resource>
</transformer>
</transformers>
<!-- end of config -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Release -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.5.3</version>
<configuration>
<useReleaseProfile>false</useReleaseProfile>
<releaseProfiles>release</releaseProfiles>
<tagNameFormat>v${project.version}</tagNameFormat>
<autoVersionSubmodules>true</autoVersionSubmodules>
</configuration>
</plugin>
<!-- Execution -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>${project.mainClass}</mainClass>
<arguments>
<!-- to be interpreted by a CLI parser.
<argument>d=0</argument>
<argument>w=320</argument>
<argument>h=200</argument>
<argument>s=2</argument>
-->
</arguments>
</configuration>
</plugin>
<!-- Surefire reporting configuration -->
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<exclude>**/*BDDTests.java</exclude>
</includes>
<!-- I know the following line is bad, but... -->
<argLine>--illegal-access=permit</argLine>
</configuration>
</plugin>
<!-- Cucumber reporting -->
<plugin>
<groupId>net.masterthought</groupId>
<artifactId>maven-cucumber-reporting</artifactId>
<version>5.6.2</version>
<executions>
<execution>
<id>execution</id>
<phase>verify</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<projectName>${project.name}</projectName>
<outputDirectory>${project.build.directory}/site/cucumber-reports</outputDirectory>
<jsonFiles>
<!-- supports wildcard or name pattern -->
<param>**/*.json</param>
</jsonFiles>
<skip>true</skip>
<mergeFeaturesById>true</mergeFeaturesById>
<buildNumber>4</buildNumber>
</configuration>
</execution>
</executions>
</plugin>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-site-plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.9.1</version>
</plugin>
<!-- packaging of the delivery solution -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>create-archive</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptors>
<descriptor>src/assembly/dep.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
<!-- Resource parsing -->
<resources>
<resource>
<directory>src/assembly/scripts</directory>
<filtering>true</filtering>
<includes>
<include>launch.sh</include>
<include>launch.bat</include>
<include>launch.ps1</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>**/*.ttf</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>**/*.ttf</include>
</includes>
</resource>
<resource>
<directory>src/changes</directory>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/docs</directory>
<filtering>false</filtering>
</resource>
</resources>
</build>
<reporting>
<plugins>
<!-- Generate the tests report -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<!-- Code coverage -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<reportSets>
<reportSet>
<reports>
<!-- select non-aggregate reports -->
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
<!-- Javadoc reporting -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.3.1</version>
<configuration>
<stylesheetfile>${project.basedir}/src/main/docs/css/site.css</stylesheetfile>
<show>public</show>
</configuration>
</plugin>
<!-- Generate the Release Notes for this version (linked to jira issues
list) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-changes-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<includeOpenIssues>false</includeOpenIssues>
<onlyMilestoneIssues>false</onlyMilestoneIssues>
<columnNames>Id,Type,Key,Summary,Assignee,Status,Fix Version</columnNames>
</configuration>
<reportSets>
<reportSet>
<reports>
<report>jira-report</report>
<report>changes-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<organization>
<name>SnapGames</name>
<url>https://snapgames.fr</url>
</organization>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment