← 返回命令列表

Linux command

mvn-compile 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Compile

mvn compile

Activate a profile

mvn compile -P [profile_name]

Compile without

mvn compile -DskipTests

Compile in offline

mvn compile -o

Force update

mvn compile -U

Run with a specific

mvn compile -Dmaven.compiler.release=[17]

Quiet compile

mvn compile -q

Compile a specific module

mvn -pl [module/path] -am compile

说明

mvn compile runs the compile phase of the Maven default lifecycle, executing all phases that come before it (validate, initialize, generate-sources, process-resources, ...) and finally invoking maven-compiler-plugin to compile src/main/java into target/classes. Resources from src/main/resources are copied during the process-resources phase, so they are available on the classpath after compile completes. The compiler version and target language level are governed by the maven-compiler-plugin configuration in pom.xml or by the maven.compiler.source, maven.compiler.target, and maven.compiler.release properties. Use -T for parallel multi-module builds, and -pl/-am to compile only the relevant module of a large reactor.

参数

-P _profile_
Activate one or more comma-separated Maven profiles.
-DskipTests
Skip test compilation in subsequent phases. Tests are still compiled if mvn test runs without this flag.
-Dmaven.compiler.release _N_
Set the --release flag passed to javac, controlling the target JDK API level.
-o, --offline
Run in offline mode; never reach out to remote repositories.
-U, --update-snapshots
Force updates of snapshot dependencies and plugins.
-pl _MODULES_
Restrict the reactor build to a comma-separated list of modules.
-am, --also-make
Together with -pl, also build dependencies of the selected modules.
-q, --quiet
Print only errors and the final result.
-X, --debug
Enable verbose debug output (full stack traces, effective POM).
-T _N_
Build in parallel using _N_ threads (or 1C for one per core).

FAQ

What is the mvn-compile command used for?

mvn compile runs the compile phase of the Maven default lifecycle, executing all phases that come before it (validate, initialize, generate-sources, process-resources, ...) and finally invoking maven-compiler-plugin to compile src/main/java into target/classes. Resources from src/main/resources are copied during the process-resources phase, so they are available on the classpath after compile completes. The compiler version and target language level are governed by the maven-compiler-plugin configuration in pom.xml or by the maven.compiler.source, maven.compiler.target, and maven.compiler.release properties. Use -T for parallel multi-module builds, and -pl/-am to compile only the relevant module of a large reactor.

How do I run a basic mvn-compile example?

Run `mvn compile` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -P _profile_ do in mvn-compile?

Activate one or more comma-separated Maven profiles.