Although I have some experience about Maven 2, this is a simple summary.
groupid:artifactid:packaging:version:scope such as: org.springframework:spring:jar:2.5.6:compile
org.mockito:mockito-core:jar:4.7:test Maven provides the following standard scope:
Lifecycles, Phases, Plugins, Goals
Lifecycles represent a well-recognized flw of steps (Phases) used in software assembly. Each step in a lifecycle flow is called a phase. Zero or more plugin goals are bound to a phase. A plugin is a logical grouping and distribution (often a single JAR) of related goals, such as JARing. A goal, the most granular step in Maven, is a single executable task within a plugin. For example, discrete goals in the jar plugin include packaging the jar (jar:jar), signing the jar (jar:sign), and verifying the signature (jar:sign-verify).
Maven provides 3 built-in lifecycles: clean, default, site.
The following lists all build phases and its default goals bound to them.
we set the packaging for your project via the equally named POM element . Some of the valid packaging values are jar, war, ear and pom. If no packaging value has been specified, it will default to jar.
Phase and goal binding
A goal may be bound to zero or more build phases. A goal not bound to any build phase could be executed outside of the build lifecycle by direct invocation.
Moreover, if a goal is bound to one or more build phases, that goal will be called in all those phases.
Furthermore, a build phase can also have zero or more goals bound to it. If a build phase has no goals bound to it, that build phase will not execute.
Usually, plugin bind its goals on default phases. That’s defined on plugin jar’s MATE-INF/maven/plugin.xml.
Let’s see the plugin.xml of maven-compiler-plugin.jar:
<plugin> <mojos> <mojo> <goal>compile</goal> .... <phase>compile</phase> .... </mojo> <mojo> <goal>help</goal> .... </mojo> <mojo> <goal>testCompile</goal> .... <phase>test-compile</phase> .... </mojo> </mojos> </plugin>
maven-compiler-plugin defines 3 goals, and “compile” and “testCompiler” goals have the default phase, but “help” goal not.
But a goal can be bound on different phases which can be reconfigured by plugin configuration section.
... <plugin> <groupId>com.mycompany.example</groupId> <artifactId>display-maven-plugin</artifactId> <version>1.0</version> <executions> <execution> <phase>process-test-resources</phase> <goals> <goal>time</goal> </goals> </execution> <execution> <phase>process-resources</phase> <goals> <goal>anotherGoal</goal> <goal>anotherGoalAgain</goal> </goals> </execution> </executions> </plugin> ...
The default goal codifis the author’s intended usage of the build script. Only one goal or lifecycle can be set as the default.
<project> [...] <build> <defaultGoal>install</defaultGoal> </build> [...] </project>
Execute a Phase or Goal
If you ask Maven to run a specific goal, then only that goal is run.
For org.apache.maven:maven-***-plugin, you can run it using the plugin-prefix for short.
mvn : or
For your customized plugins, run it:
mvn :[:]: For example: mvn compiler:compile jar:jar This example runs two plugin goals: compilation of code, then JARing the result, skipping over any intermediate steps.
Conversely, if you ask Maven to execute a phase, all phases and bound plugin goals up to that point in the lifecycle are also executed. This example requests the deploy lifecycle phase, which will also execute the verifiation, compilation, testing and packaging phases.
Profies are a means to conditionally turn on portions of Maven confiuration, including plugins, pathing and confiuration. The most common uses of profies are for Windows/Unix platform-specifi variations and build-time customization of JAR dependencies based on the use of a specifi Weblogic, Websphere or JBoss J2EE vendor.
<project> ... <profiles> <profile> <id>YourProfile</id> ...settings, build, plugins etc... <dependencies> <dependency> <groupId>com.yourcompany</groupId> <artifactId>yourlib</artifactId> </dependency> <dependencies> </profile> </profiles> ... </project>
Profiles can be activated manually from the command line or through an activation rule (OS, fie existence, Maven version, etc.).
Profiles are primarily additive, so best practices suggest leaving most off by default, and activating based on specific conditions.
Manual Profie Activation
mvn –P YourProfie Automatic Profie Activation
<project> ... <profiles> <profile> <id>YourProfile</id> ...settings, build, etc... <activation> <os> <name>Windows XP</name> <family>Windows</family> <arch>x86</arch> <version>5.1.2600</version> </os> <fie> <missing>somefolder/somefie.txt</missing> </fie> </activation> </profile> </profiles> ... </project>