100 likes | 405 Views
Maven . Next generation build and project setup tool. Why another build tool?. Every Ant script is different. Why? Maven uses convention over configuration Maven conventions make it easier to learn a new project Ant can be flexible
E N D
Maven Next generation build and project setup tool
Why another build tool? • Every Ant script is different. Why? • Maven uses convention over configuration • Maven conventions make it easier to learn a new project • Ant can be flexible • Maven and Ant are not incompatible - you can use the strengths of both
Build lifecycle • With Ant, you have to define your own build lifecycle. • Maven defines a standard build lifecycle for each type of project - jar, war, ear, etc. • The actual work is performed by Maven ‘plugins’, which are wired to different phases of the build lifecycle. The default wiring is sufficient for most projects. • The default lifecycles allow most projects to be built automatically, with minimum configuration
Configuring Maven • Every module in your project has a maven xml configuration file called a POM (project object model). • Each module has a ‘packaging’ type. When you build that module this determines the type of ‘artifact’ which results, and the build lifecycle eg .jar, .war or .ear • Each built artifact has a group and name to identify it, plus a version - defined in the .pom ath the point the build took place. • Over time, the version number will be incremented.
Dependency management in Maven • Nothing in Ant helps you manage dependencies between modules. • Maven can manage your dependencies for you - using the concept of an ‘Artifact Repository’ • Set up your module’s dependencies by listing them in the .pom • When the Maven build runs, Maven will look for the dependencies in your local artifact repository
Maven Repositories - local and remote • Maven repositories are nothing more than a set of folders containing versioned artifacts (.jars, .wars etc) and their matching .poms • They conform to a well know directory structure, based on module group, name and version • A Maven repository can be set up under a web server, so the contents can be served • Maven build will look for a dependency in your local repository first, then try your team’s repository, and finally the maven central repository – it is a bit like DNS
Transitive dependencies in maven • Why include the .poms in the artifact repository? • Maven can automatically go and find your dependencies for you, including all the indirect ‘transitive’ dependencies. • From version 7, Intellij can read your .poms and autoconfigure your Intellij project, downloading any required libraries and.
Other Maven features Plugins
Common problems Missing artifacts. Not every project is a Maven project (yet!)- use maven install:install-file Maven central repository can be slow (set up your maven configuration to use the mirrors) Finding the documentation. Each plugin has its own documentation. Use the links on our wiki.