Maven: Difference between revisions

From Wiki RB4
No edit summary
No edit summary
Line 48: Line 48:
  <build>
  <build>
   ...
   ...
  <plugins>
  </plugins>
  </build>
  </build>
====<plugin>====


==Operation==
==Operation==

Revision as of 20:48, 8 January 2012

Introduction

Maven is an attempt to apply patterns to a project's build infrastructure in order to promote comprehension and productivity by providing a clear path in the use of best practices. Maven is essentially a project management and comprehension tool and as such provides a way to help with managing:

  • Builds
  • Documentation
  • Reporting
  • Dependencies
  • SCMs
  • Releases
  • Distribution

Maven beinhaltet als wichtiges Konzept genau definierte Build Lifecycles. Die drei Standard-Lifecycle sind: clean, default und site. Build Lifecycles bestehen aus Lifecycle-Phasen. Wichtige Phasen sind beispielsweise: clean, compile, test, package, integration-test, verify, install, deploy und site. In den Lifecycle-Phasen werden jeweils bestimmte Plugin-Goals ausgeführt. Maven-Plugins sind Bibliotheken, die thematisch zusammengehörende Goals implementieren. Wichtige Plugins sind zum Beispiel: archetype, compiler, surefire, jar, war, install, deploy, site, dependency, eclipse und jetty. Goals können bestimmten Lifecycle-Phasen zugeordnet werden und werden dann automatisch zum richtigen Zeitpunkt aufgerufen (z.B. "compiler:compile"). Maven-Goals sind vergleichbar mit Ant-Tasks.

Ein Maven-Archetype ist ein Projekt-Template. Über das archetype-Plugin können Standard-Directory-Layouts und Projektvorlagen für verschiedene Projekttypen erstellt werden (z.B. quickstart, webapp und mojo). Dabei wird auch eine vorläufige pom.xml angelegt.

Artefakt sind im Zusammenhang mit Maven Arbeitsergebnisse gemeint. Maven-Projekte haben in der Regel ein Hauptergebnis-Artefakt, oft eine jar-, war- oder ear-Datei. Mit Koordinaten werden die fünf ein Artefakt identifizierenden Informationsbestandteile bezeichnet. Oft sind vor allem die drei wichtigsten gemeint: groupId, artifactId und version.

Installation

Configuration

All information is stored in pom.xml (Project Object Model).

pom.xml

<project>

<project>
  <modelVersion> </modelVersion>
  <groupId> </groupId> <!-- organization identifier e.g. www.uweheuer.de -->
  <artefactId> </artefactId> <!-- base name of the primary artefact extended with version and extension -->
  <packaging> </packaging> <!-- package type with impact on the lifecycle -->
  <version> </version>
  <name> </name> <!-- for documentation -->
  <url> </url> <!-- for documentation -->
  <description> </description> <!-- for documentation -->
  <build>...</build>
</project>

<build>

<build>
  ...
  <plugins>
  </plugins>
</build>


<plugin>

Operation

mvn archetype:generate -DarchetypeGroupId=org.apache.maven.archetypes -DgroupId=com.mycompany.app -DartifactId=my-app
mvn <cmd> -Dverbose
mvn clean
mvn compile
mvn test  // delete all artefacts and target dir
mvn package // build artefacts

Resources