Links#
https://maven.apache.org/wrapper/
https://maven.apache.org/guides/mini/guide-using-toolchains.html
https://maven.apache.org/configure.html
1. Important Points#
build environment:
Maven version
JDK used to run Maven
JDK used to compile project
Maven default options
repository settings
2. Maven Wrapper#
mvn wrapper:wrapper
./mvnw -v
commit:
mvnw
mvnw.cmd
.mvn/wrapper/maven-wrapper.properties
use:
./mvnw in local dev and CI
3. .mvn/maven.config#
maven.config:
project-local default Maven CLI options
keep it small because every Maven command reads it
4. .mvn/jvm.config#
-Xmx1g
-Dfile.encoding=UTF-8
jvm.config:
JVM options for the Maven process itself
not the application runtime JVM
<!-- ~/.m2/toolchains.xml -->
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>21</version>
<vendor>temurin</vendor>
</provides>
<configuration>
<jdkHome>/opt/jdk-21</jdkHome>
</configuration>
</toolchain>
</toolchains>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<goals>
<goal>toolchain</goal>
</goals>
</execution>
</executions>
<configuration>
<toolchains>
<jdk>
<version>21</version>
<vendor>temurin</vendor>
</jdk>
</toolchains>
</configuration>
</plugin>
toolchains:
Maven can run on one JDK and compile with another JDK
6. Verify#
./mvnw -v
./mvnw help:effective-settings
./mvnw help:effective-pom
7. Offline And Cache#
./mvnw -B dependency:go-offline
./mvnw -o test
dependency:go-offline:
prefetch dependencies and plugins for later build
-o:
offline mode, fails if required artifacts are missing locally
8. Checklist#
check:
Maven Wrapper committed
CI uses ./mvnw
Java version enforced by enforcer
compiler release configured
toolchains used when multiple JDKs exist