Maven Build Environment

验证:未记录
适用版本
未记录
验证范围
尚未登记验证记录。

本文缩写(英文全称与中文含义)
缩写 英文全称/名称 中文含义
CI Continuous Integration 持续集成
CLI Command-Line Interface 命令行接口
JDK Java Development Kit Java 开发工具包
JVM Java Virtual Machine Java 虚拟机
UTF Unicode Transformation Format Unicode 转换格式
https://maven.apache.org/wrapper/
https://maven.apache.org/guides/mini/guide-using-toolchains.html
https://maven.apache.org/configure.html

1. Important Points#

.mvn/jvm.config 配置运行 Maven 本身的 JVM,不是应用 runtime JVM;Maven 版本、编译 JDK 和应用运行 JDK 分别确认。

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#

-B
-Dstyle.color=always
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

5. Toolchains#

<!-- ~/.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

搜索文档

输入关键词,搜索所有文档。

↑ ↓ 选择 · Enter 打开 · Esc 关闭