问题
I'm new to Maven, coming from the Ant world.
Is it possible to list all of the possible goals (including, say, all the plugins) that you can run?
I can see that there used to be a -g
flag in Maven 1, but this isn't available in version 2.
回答1:
The goal you indicate in the command line is linked to the lifecycle of Maven. For example, the build
lifecycle (you also have the clean
and site
lifecycles which are different) is composed of the following phases:
validate
: validate the project is correct and all necessary information is available.compile
: compile the source code of the project.test
: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed.package
: take the compiled code and package it in its distributable format, such as a JAR.integration-test
: process and deploy the package if necessary into an environment where integration tests can be run.verify
: run any checks to verify the package is valid and meets quality criteriainstall
: install the package into the local repository, for use as a dependency in other projects locally.deploy
: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
You can find the list of "core" plugins here, but there are plenty of others plugins, such as the codehaus ones, here.
回答2:
Is it possible to list all of the possible goals (including, say, all the plugins) that it is possible to run?
Maven doesn't have anything built-in for that, although the list of phases is finite (the list of plugin goals isn't since the list of plugins isn't).
But you can make things easier and leverage the power of bash completion (using cygwin if you're under Windows) as described in the Guide to Maven 2.x auto completion using BASH (but before to choose the script from this guide, read further).
To get things working, first follow this guide to setup bash completion on your computer. Then, it's time to get a script for Maven2 and:
- While you could use the one from the mini guide
- While you use an improved version attached to MNG-3928
- While you could use a random scripts found around the net (see the resources if you're curious)
- I personally use the Bash Completion script from Ludovic Claude's PPA (which is bundled into the packaged version of
maven
in Ubuntu) that you can download from the HEAD. It's simply the best one.
Below, here is what I get just to illustrate the result:
$ mvn [tab][tab] Display all 377 possibilities? (y or n) ant:ant ant:clean ant:help antrun:help antrun:run archetype:crawl archetype:create archetype:create-from-project archetype:generate archetype:help assembly:assembly assembly:directory assembly:directory-single assembly:help assembly:single ...
Of course, I never browse the 377 possibilities, I use completion. But this gives you an idea about the size of "a" list :)
Resources
- Guide to Maven 2.x auto completion using BASH
- Fixing Maven 2.x BASH auto completion on CYGWIN
- Maven bash completion
- maven2 bash completion complete
- Maven Tab Auto Completion in Bash
- Advanced Bash completion script for Maven 2
回答3:
If you use IntelliJ IDEA you can browse all maven goals/tasks (including plugins) in Maven Projects
tab:
回答4:
Lets make it very simple:
Maven Lifecycles: 1. Clean 2. Default (build) 3. Site
Maven Phases of the Default Lifecycle: 1. Validate 2. Compile 3. Test 4. Package 5. Verify 6. Install 7. Deploy
Note: Don't mix or get confused with maven goals with maven lifecycle.
See Maven Build Lifecycle Basics1
回答5:
A Build Lifecycle is Made Up of Phases
Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.
For example, the default lifecycle comprises of the following phases (for a complete list of the lifecycle phases, refer to the Lifecycle Reference):
- validate - validate the project is correct and all necessary information is available
- compile - compile the source code of the project
- test - test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
- package - take the compiled code and package it in its distributable format, such as a JAR. verify - run any checks on results of integration tests to ensure quality criteria are met
- install - install the package into the local repository, for use as a dependency in other projects locally
- deploy - done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
These lifecycle phases (plus the other lifecycle phases not shown here) are executed sequentially to complete the default lifecycle. Given the lifecycle phases above, this means that when the default lifecycle is used, Maven will first validate the project, then will try to compile the sources, run those against the tests, package the binaries (e.g. jar), run integration tests against that package, verify the integration tests, install the verified package to the local repository, then deploy the installed package to a remote repository.
Source: https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
来源:https://stackoverflow.com/questions/3996802/list-all-of-the-possible-goals-in-maven-2