Introduction to Maven

The Build Lifecycle
• 3 Built-in Lifecycles:
– Default
• Project deployment

– Clean
• Project Cleaning

– Site
• Project Documentation

for use as a dependency in other projects locally Deploy – Done in an integration or release environment. – 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. – Copies the final package to the remote repository for sharing with other developers and projects. 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 criteria Install – – Install the package into the local repository.Lifecycle 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. .

process-resources 2. install 8. deploy . test-compile 5. package 7. process-test-resources 4.Default Lifecycle • • • • • • • • 1. test 6. compile 3.

.

.

it wont execute .Build Phase Goals • Specific tasks that contributes to building and managing a project • Can be bound to 0 or more phases • Unbound goals can be executed directly • Order of execution depends on order of definition and order of build phases • If no goals bound to a build phase.

Setting up • Packaging – Defaults to jar process-resources compile process-test-resources test-compile test package install deploy resources:resources compiler:compile resources:testResources compiler:testCompile surefire:test jar:jar install:install deploy:deploy .

Plugins • Artifacts that provide goals • 1 or more goals each representing a specific capability – Compile. test-compile – Executions to gain control over order in which goals are executed • Usage: mvn [plugin-name]:[goal-name] • Eg: – mvn compiler:compile – mvn surefire:test – mvn jar:jar .

.

.

Configuring Plugins • Build Plugins – Configure using executions • Reporting Plugins .

.

.

.

.

Dependencies .

• provided: A provided dependency is used to compile the application. • runtime: Runtime-scope dependencies are not needed for compilation. The servlet APIs are a good example. You would use this scope when you expect the JDK or application server to provide the JAR. This is the default value. only for execution. for example). but will not be deployed. • test: Test-scope dependencies are needed only to compile and run tests (JUnit. .Dependencies • compile: A compile-scope dependency is available in all phases. such as JDBC (Java Database Connectivity) drivers.

m2/settings. • Global – Defined in the global Maven-settings (%M2_HOME%/conf/settings. • Per User – Defined in the Maven-settings (%USER_HOME%/.xml).xml).Profiles • Per Project – Defined in the POM itself (pom. .xml).

.

. • Activation by default • Explicit activation through command line.environment..Activating Profiles • Conditional activation • Based on OS.. state of project etc.

m2″. you need to add some remote repositories to download the libraries from another location instead of the default central repository. often times.Plugin Repositories • Central – Maven central repository is the default location for Maven to download all the project dependency libraries. you may need to change it to another folder. • Remote – Not all libraries are store in Maven central repository. • Local – Maven local repository is used to store the project dependency libraries. . and the default folder is “.

Sign up to vote on this title
UsefulNot useful