Linux command
mvn-generate-sources 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate sources
mvn generate-sources
Generate with profile
mvn generate-sources -P [profile]
Generate offline
mvn generate-sources -o
说明
mvn generate-sources invokes Maven's generate-sources lifecycle phase, which (along with all earlier phases — validate, initialize) runs any plugin executions bound to it. This is where code generators belong: JAXB / XJC, gRPC / Protocol Buffers, Avro, Antlr, OpenAPI, Modello, JOOQ, etc. Generated sources usually land under target/generated-sources/_plugin_/ and are added to the compile source roots automatically when the next phase, process-sources → compile, runs. Because Maven runs every preceding phase as well, mvn generate-sources is rarely the most useful command on its own — most users invoke mvn compile or mvn package and let generation happen as a side effect. Use this phase explicitly when you want generated code available for IDE refresh without compiling the whole project.
参数
- -P _profile_,_profile_...
- Activate one or more build profiles defined in pom.xml or settings.xml.
- -o, --offline
- Work offline (do not contact remote repositories).
- -U, --update-snapshots
- Force a check for updated SNAPSHOT dependencies and plugin releases.
- -X, --debug
- Enable debug-level Maven output.
- -pl _modules_, --projects _modules_
- Restrict the build to the listed reactor modules (comma-separated).
- -am, --also-make
- Build also the projects required by the ones selected with -pl.
- -T _N_C, --threads _N_C
- Use _N_ threads, optionally per CPU core (e.g. -T 1C).
- -D_property_=_value_
- Pass a system property to the build.
FAQ
What is the mvn-generate-sources command used for?
mvn generate-sources invokes Maven's generate-sources lifecycle phase, which (along with all earlier phases — validate, initialize) runs any plugin executions bound to it. This is where code generators belong: JAXB / XJC, gRPC / Protocol Buffers, Avro, Antlr, OpenAPI, Modello, JOOQ, etc. Generated sources usually land under target/generated-sources/_plugin_/ and are added to the compile source roots automatically when the next phase, process-sources → compile, runs. Because Maven runs every preceding phase as well, mvn generate-sources is rarely the most useful command on its own — most users invoke mvn compile or mvn package and let generation happen as a side effect. Use this phase explicitly when you want generated code available for IDE refresh without compiling the whole project.
How do I run a basic mvn-generate-sources example?
Run `mvn generate-sources` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -P _profile_,_profile_... do in mvn-generate-sources?
Activate one or more build profiles defined in pom.xml or settings.xml.