Extract Coordinates from the POM
Helpful for build and integration environments, pipelines etc.
mvn org.apache.maven.plugins:maven-help-plugin:3.1.0:evaluate -Dexpression=project.version -q -DforceStdout
Override a Property via local configuration
e.g. to override the property xxx
from your project’s pom.xml
-
Create a directory
.mvn
in your project directory root -
Create a file named
maven.config
in this directory -
Insert
-Dxxx=newvalue
into the file to override this property
Don’t forget to add .mvn to your .gitignore!
|
Search for specific dependency in dependency tree
e.g. for Apache Http Client, groupId: org.apache.httpcomponents
, artifactId: httpclient
:
mvn dependency:tree -Dincludes=org.apache.httpcomponents:httpclient
Dirty Replace javax.* packages with jakarta equivalent
May be used as a workaround until the maven-jaxb2-plugin supports JakartaEE 9
|
Using the maven-replacer-plugin
…
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>replace-import-javax-by-jakarta</id>
<phase>process-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>
${project.build.directory}/generated-sources/
</basedir>
<includes>
<include>core/**/*.java</include>
</includes>
<replacements>
<replacement>
<token>javax.annotation.</token>
<value>jakarta.annotation.</value>
</replacement>
<replacement>
<token>javax.xml.bind.</token>
<value>jakarta.xml.bind.</value>
</replacement>
</replacements>
</configuration>
</plugin>
Colourize output
export MAVEN_COLOR=true
Add build number via resource filtering
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<doCheck>true</doCheck>
<shortRevisionLength>7</shortRevisionLength>
</configuration>
</plugin>
Afterwards the following placeholder may be used in a filtered resource in src/main/resources: ${buildNumber}
Pass JVM Arguments
On the command line:
mvn -DargLine="-Xmx8192m" compile
Since Maven 3.3.1 with a file in the project baseDir .mvn/jvm.config that contains this parameter .. e.g.:
-DargLine="-Xmx8192m"
Run build with 4 threads
mvn -T 4 clean install
Run build with 2 threads per core
mvn -T 2C clean install
Setup Maven Wrapper with local settings.xml
Create a file named maven.config
in .mvn
also as the designated settings.xml
.
The maven.config
contains this entry:
-s .mvn\settings.xml
Restrict Resource Filtering to Specific Files
E.g. filtering only one specific property file:
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>db/dbmigrations/liquibase.properties</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>db/dbmigrations/liquibase.properties</exclude>
</excludes>
</resource>
</resources>
Write Git Version Information to Properties File
Used here the Maven git-commit-id-plugin
:
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.6</version>
<configuration>
<generateGitPropertiesFilename>${project.build.outputDirectory}/gitinfo.properties
</generateGitPropertiesFilename>
<prefix>git</prefix>
<includeOnlyProperties>
<includeOnlyProperty>git.build.version</includeOnlyProperty>
<includeProperty>^git.commit.id$</includeProperty>
<includeProperty>git.build.time</includeProperty>
</includeOnlyProperties>
</configuration>
</plugin>
Maven Plugin and Goal Information
Using the Maven Help plugin like this:
mvn help:describe -Dplugin=groupid:artifactid -Dgoal=thegoal -Ddetail=true
JIRA example:
atlas-mvn help:describe -Dplugin=com.atlassian.maven.plugins:maven-jira-plugin -Dgoal=compress-resources -Ddetail=true
JPMS Module Opens and Exports for JDK Modules and internal APIs
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Add-Exports>java.base/jdk.internal.ref</Add-Exports>
<Add-Opens>java.base/java.lang java.base/java.nio java.base/sun.nio.ch</Add-Opens>
</manifestEntries>
</archive>
</configuration>
</plugin>
Adjust java source/target version for compiler
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Or using the following properties:
<properties>
<maven.compiler.source>1.9</maven.compiler.source>
<maven.compiler.target>1.9</maven.compiler.target>
</properties>
Show effective pom
mvn help:effective-pom