Skip to content

Instantly share code, notes, and snippets.

@LIttleAncientForestKami
Last active September 24, 2023 15:41
Show Gist options
  • Save LIttleAncientForestKami/c9b185c123fc97f6022861f645766aa5 to your computer and use it in GitHub Desktop.
Save LIttleAncientForestKami/c9b185c123fc97f6022861f645766aa5 to your computer and use it in GitHub Desktop.
Maven POM with UTF8 encoding, compiler props, maven plugins (compiler, resources, jar) and sources for why
<?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>pl.lafk</groupId>
<artifactId>#APP</artifactId>
<version>0.1</version>
<name>#NAME</name>
<description>#DESC</description>
<url>lafk.pl</url>
<properties>
<!-- https://maven.apache.org/general.html#encoding-warning -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- https://maven.apache.org/general.html#special-characters-site -->
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.java.version>17</project.java.version>
<maven.compiler.release>${project.java.version}</maven.compiler.release>
<!-- IntelliJ HAS issues with just release and tries to add source/target so adding them here -->
<maven.compiler.source>${project.java.version}</maven.compiler.source>
<maven.compiler.target>${project.java.version}</maven.compiler.target>
<!-- see source for the plugins to verify if those can be skipped, they should IIRC -->
<maven.compiler.encoding>${project.build.sourceEncoding}</maven.compiler.encoding>
<maven.resources.encoding>${project.build.sourceEncoding}</maven.resources.encoding>
<!-- security wise - Maven jumped from 3.6.3 ALL THE WAY to 3.8.1!
Quite important for security and compatibility-breaking change: insecure URLs are now disallowed
More: https://maven.apache.org/docs/3.8.1/release-notes.html
-->
<version.maven>3.8.3</version.maven>
<!-- plugin versions should go here, so below they can be omitted -->
<version.plugin.maven.enforcer>3.0.0-M2</version.plugin.maven.enforcer>
<version.plugin.maven.jar>3.1.0</version.plugin.maven.jar>
<version.plugin.maven.compiler>3.8.0</version.plugin.maven.compiler>
<version.plugin.maven.resources>3.1.0</version.plugin.maven.resources>
<!-- dependencies versions -->
<version.testng>7.4.0</version.testng>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${version.testng}</version>
<scope>test</scope>
</dependency>
<!-- #Your dependencies -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${version.plugin.maven.enforcer}</version>
<executions>
<execution>
<id>enforce-maven</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireMavenVersion>
<!-- helps with plugin versions, so you are more up-to-date -->
<version>${version.maven}</version>
</requireMavenVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${version.plugin.maven.jar}</version>
<configuration>
<archive>
<index>true</index>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>#FQN of your MainClass</mainClass>
</manifest>
<manifestEntries>
<mode>development</mode>
<url>${project.url}</url>
<key>value</key>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${version.plugin.maven.compiler}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- if diff enconding than UTF8 is needed: https://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html -->
<version>${version.plugin.maven.resources}</version>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment