6.5Maven常用命令一览表

1.句法

mvn [options] [<goal(s)>] [<phase(s)>]

2.插件以及目标(goal)

plugin:goal
PluginDescription
Core pluginsPlugins corresponding to default core phases (ie. clean, compile). They may have multiple goals as well.
cleanClean up after the build.
compilerCompiles Java sources.
deployDeploy the built artifact to the remote repository.
failsafeRun the JUnit integration tests in an isolated classloader.
installInstall the built artifact into the local repository.
resourcesCopy the resources to the output directory for including in the JAR.
siteGenerate a site for the current project.
surefireRun the JUnit unit tests in an isolated classloader.
verifierUseful for integration tests – verifies the existence of certain conditions.
Packaging types/toolsThese plugins relate to packaging respective artifact types.
earGenerate an EAR from the current project.
ejbBuild an EJB (and optional client) from the current project.
jarBuild a JAR from the current project.
rarBuild a RAR from the current project.
warBuild a WAR from the current project.
app-client/acrBuild a JavaEE application client from the current project.
shadeBuild an Uber-JAR from the current project, including dependencies.
sourceBuild a source-JAR from the current project.
jlinkBuild Java Run Time Image.
jmodBuild Java JMod files.
Reporting pluginsPlugins which generate reports, are configured as reports in the POM and run under the site generation lifecycle.
changelogGenerate a list of recent changes from your SCM.
changesGenerate a report from an issue tracker or a change document.
checkstyleGenerate a Checkstyle report.
doapGenerate a Description of a Project (DOAP) file from a POM.
docckDocumentation checker plugin.
javadocGenerate Javadoc for the project.
jdepsRun JDK’s JDeps tool on the project.
jxrGenerate a source cross reference.
linkcheckGenerate a Linkcheck report of your project’s documentation.
pmdGenerate a PMD report.
project-info-reportsGenerate standard project reports.
surefire-reportGenerate a report based on the results of unit tests.
ToolsThese are miscellaneous tools available through Maven by default.
antrunRun a set of ant tasks from a phase of the build.
artifactManage artifacts tasks like buildinfo.
archetypeGenerate a skeleton project structure from an archetype.
assemblyBuild an assembly (distribution) of sources and/or binaries.
dependencyDependency manipulation (copy, unpack) and analysis.
enforcerEnvironmental constraint checking (Maven Version, JDK etc), User Custom Rule Execution.
gpgCreate signatures for the artifacts and poms.
helpGet information about the working environment for the project.
invokerRun a set of Maven projects and verify the output.
jarsignerSigns or verifies project artifacts.
jdeprscanRun JDK’s JDeprScan tool on the project.
patchUse the gnu patch tool to apply patch files to source code.
pdfGenerate a PDF version of your project’s documentation.
pluginCreate a Maven plugin descriptor for any mojos found in the source tree, to include in the JAR.
releaseRelease the current project – updating the POM and tagging in the SCM.
remote-resourcesCopy remote resources to the output directory for inclusion in the artifact.
scmExecute SCM commands for the current project.
scm-publishPublish your Maven website to a scm location.
scriptingThe Maven Scripting Plugin wraps the Scripting API according to JSR223.
stageAssists with release staging and promotion.
toolchainsAllows to share configuration across plugins.
wrapperDownload and unpack the maven wrapper distribution (works only with Maven 4)

Retired

PluginType*VersionRetired DateDescription
antB2.42019-06-02Generate an Ant build file for the project.
eclipseB2.102015-10-07Generate an Eclipse project files for the current project.
ideaB2.2.12013-07-26Create/update an IDEA workspace for the current project (individual modules are created as IDEA modules)
oneB1.32013-07-30A plugin for interacting with legacy Maven 1.x repositories and builds.
reactorB1.12014-03-24Build a subset of interdependent projects in a reactor (Maven 2 only).
repositoryB2.42019-04-30Plugin to help with repository-based tasks.

At MojoHaus

PluginDescription
animal-snifferBuild signatures of APIs (JDK for example) and checks your classes against them.
build-helperAttach extra artifacts and source folders to build.
castorGenerate sources from an XSD using Castor.
clirrCompare binaries or sources for compatibility using Clirr
javaccGenerate sources from a JavaCC grammar.
jdependGenerate a report on code metrics using JDepend.
nar-maven-pluginCompiles C, C++, Fortran for different architectures.
nativeCompiles C and C++ code with native compilers.
sqlExecutes SQL scripts from files or inline.
taglistGenerate a list of tasks based on tags in your code.
versionsManage versions of your project, its modules, dependencies and plugins.

Misc

PluginDescription
cargoStart/stop/configure J2EE containers and deploy to them.
cloverGenerate a Clover report.
jettyJetty Run a Jetty container for rapid webapp development.
jalopyUse Jalopy to format your source code.
ratRelease Audit Tool (RAT) to verify files.
Genesis PluginsVerify legal files in artifacts.
Apache TomcatRun an Apache Tomcat container for rapid webapp development.
OWASP dependency-checkRun OWASP Dependency-Check, a utility that identifies project dependencies and checks if there are any known, publicly disclosed, vulnerabilities.
CycloneDXGenerate Software Bill of Materials (SBOM) in CycloneDX format.
pgpverifyVerify PGP signature of all project dependencies.
buildplanInspect the lifecycle of your build.

3.生命周期以及阶段(phase)

Clean Lifecycle

PhaseDescription
pre-cleanexecute processes needed prior to the actual project cleaning
cleanremove all files generated by the previous build
post-cleanexecute processes needed to finalize the project cleaning

Default Lifecycle

PhaseDescription
validatevalidate the project is correct and all necessary information is available.
initializeinitialize build state, e.g. set properties or create directories.
generate-sourcesgenerate any source code for inclusion in compilation.
process-sourcesprocess the source code, for example to filter any values.
generate-resourcesgenerate resources for inclusion in the package.
process-resourcescopy and process the resources into the destination directory, ready for packaging.
compilecompile the source code of the project.
process-classespost-process the generated files from compilation, for example to do bytecode enhancement on Java classes.
generate-test-sourcesgenerate any test source code for inclusion in compilation.
process-test-sourcesprocess the test source code, for example to filter any values.
generate-test-resourcescreate resources for testing.
process-test-resourcescopy and process the resources into the test destination directory.
test-compilecompile the test source code into the test destination directory
process-test-classespost-process the generated files from test compilation, for example to do bytecode enhancement on Java classes.
testrun tests using a suitable unit testing framework. These tests should not require the code be packaged or deployed.
prepare-packageperform any operations necessary to prepare a package before the actual packaging. This often results in an unpacked, processed version of the package.
packagetake the compiled code and package it in its distributable format, such as a JAR.
pre-integration-testperform actions required before integration tests are executed. This may involve things such as setting up the required environment.
integration-testprocess and deploy the package if necessary into an environment where integration tests can be run.
post-integration-testperform actions required after integration tests have been executed. This may including cleaning up the environment.
verifyrun any checks to verify the package is valid and meets quality criteria.
installinstall the package into the local repository, for use as a dependency in other projects locally.
deploydone in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

Site Lifecycle

PhaseDescription
pre-siteexecute processes needed prior to the actual project site generation
sitegenerate the project’s site documentation
post-siteexecute processes needed to finalize the site generation, and to prepare for site deployment
site-deploydeploy the generated site documentation to the specified web server

4.生命周期绑定

Maven 生命周期是抽象的,其本身不能做任何实际工作,这些实际工作(如源代码编译)都通过调用 Maven 插件 中的插件目标(plugin goal)完成的。

Clean Lifecycle Bindings

Phaseplugin:goal
cleanclean:clean

Default Lifecycle Bindings – Packaging ejb / ejb3 / jar / par / rar / war

Phaseplugin:goal
process-resourcesresources:resources
compilecompiler:compile
process-test-resourcesresources:testResources
test-compilecompiler:testCompile
testsurefire:test
packageejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war
installinstall:install
deploydeploy:deploy

Default Lifecycle Bindings – Packaging ear

Phaseplugin:goal
generate-resourcesear:generate-application-xml
process-resourcesresources:resources
packageear:ear
installinstall:install
deploydeploy:deploy

Default Lifecycle Bindings – Packaging maven-plugin

Phaseplugin:goal
generate-resourcesplugin:descriptor
process-resourcesresources:resources
compilecompiler:compile
process-test-resourcesresources:testResources
test-compilecompiler:testCompile
testsurefire:test
packagejar:jar and plugin:addPluginArtifactMetadata
installinstall:install
deploydeploy:deploy

Default Lifecycle Bindings – Packaging pom

Phaseplugin:goal
package
installinstall:install
deploydeploy:deploy

Site Lifecycle Bindings

Phaseplugin:goal
sitesite:site
site-deploysite:deploy

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/back/java/6905.html

发表评论

登录后才能评论