Tuesday, June 21, 2011

What's up with Maven?

Draft of Notes:

Yes, you must be thinking about what is up with Maven, if you just heard about it, but did not have a date with it.

Highlights:

Maven features the build, dependency management (including reflexive) tool mainly for Java programming language, resolves dependencies, supports multi-module projects.

You must have heard about Ant: it is a build only tool, written in script. Both are XML based.

So I can say Maven is a super-set of what Ant provides.

Installation: Refer to apache site

Let us check on the concepts, terms in Maven:

It covers build, test, deploy of any given Java project; the outcome would be .jar, .war or .ear file.

In Ant, it has build.xml script, Maven has got pom.xml file. Yes, in long, it is call Project Object Model, based on Xml schema.

It has got default life cycle (named 'install'); containing ordered execution of plugins; each plugin has goals, default is declared.
Defaults are good are called as Convention. If it has to be customized; it is called Configuration. In short, it is also called as Convention over Configuration.

Default life cycle ->Phases: each phase is represented by Plugin and a default goal:

Phases in order: these phases can be individually be invoked using commands

Validate
Compile -> mvn compile
Test -> mvn test
Package -> mvn package
Integration-test
Verify
Install
Deploy

Notice, when mvn install is run, all the phases upto install will be run in sequence.

mvn clean: life cycle phases -> pre-clean, clean, post-clean

To run mvn command, you must specify a valid lifecycle phase or a goal in the format
plugin-prefix:goal or plugin-group-id:plugin-artifact-id:[]:goal

Available lifecycle phases are:
validate, initialize, generate-sources, process-sources, generate-resources, process-resources, compile, process-classes, generate-test-sources, process-test-sources, generate-test-resources, process-test-resources, test-compile, process-test-classes, test, prepare-package, package, pre-integration-test, integration-test, post-integration-test, verify, install, deploy, pre-clean, clean, post-clean, pre-site, site, post-site, site-deploy.

Sample commands; invokes default life cycle
mvn clean
mvn install
mvn clean install
mvn site

No comments: