Maven

Aus Claudio's Wiki
Version vom 23. Januar 2015, 14:35 Uhr von Claudio (Diskussion | Beiträge)

(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)
Wechseln zu: Navigation, Suche

Build Lifecycle

Each of these build lifecycles is defined by a different list of build phases, wherein a build phase represents a stage in the lifecycle.

For example, the default lifecycle has the following build phases (for a complete list of the build phases, refer to the Lifecycle Reference):

  1. validate: validate the project is correct and all necessary information is available
  2. compile: compile the source code of the project
  3. test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  4. package: take the compiled code and package it in its distributable format, such as a JAR.
  5. integration-test: process and deploy the package if necessary into an environment where integration tests can be run
  6. verify: run any checks to verify the package is valid and meets quality criteria
  7. install: install the package into the local repository, for use as a dependency in other projects locally
  8. deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.


see: maven.apache.org lifecycle

Tipps & Tricks

Oft kommt es vor, dass in Eclipse die Sourcen oder die JavaDocs fehlen. Mit diesem Befehl können sie runtergeladen werden:

mvn eclipse:eclipse -DdownloadSources=true -DdownloadJavadocs=true

Sollte dies aus irgend einem Grund nicht klappen, gibts diese, aufwändigere Variante:

  1. Die gesuchten Dateien (sources und javadocs) manuell runterladen und auf der Festplatte speichern
  2. Der vorhin ausgeführte Befehl mvn eclipse:eclipse sollte unter Anderem folgenden (oder ähnlichen) Output generieren:
Sources for some artifacts are not available.
Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sources.
List of artifacts without a source archive:
  o commons-beanutils:commons-beanutils-core:1.7.0
  o commons-i18n:commons-i18n:0.5
  o org.apache.commons:commons-cli:1.1

Javadoc for some artifacts is not available.
Please run the same goal with the -DdownloadJavadocs=true parameter in order to check remote repositories for javadoc.
List of artifacts without a javadoc archive:
  o log4j:log4j:1.2.8
  o commons-i18n:commons-i18n:0.5

(evtl. vorher

mvn eclipse:clean
mvn clean

ausführen)

Wichtig ist jetzt die Liste, die Maven ausspuckt (List of artifacts without a javadoc archive:)

Der Erste Teil vor dem Doppelpunkt ist die Bezeichnung von groupId, der zweite Teil artifactId, der dritte Teil version

Jetzt kann man folgenden Befehl eingeben:

mvn install:install-file -Dfile=%DateiPfad% -DgroupId=%groupId% -DartifactId=%artifactId% -Dversion=%version% \
-Dpackaging=jar -Dclassifier=javadoc

Befehl funktioniert mit \ nur unter Linux, Windows ist dafür zu dämlich...

Für die Sourcen muss man -Dclassifier=javadoc durch -Dclassifier=sources ersetzen.

Die Variablen zwischen den % müssen entsprechend angepasst werden. Nach dem nächsten mvn eclipse:eclipse und einem Neustart von Eclipse sollten die Sourcen bzw. die JavaDocs vorhanden sein.

Quellen für Javadocs und Sourcen


Javadoc und Sources immer mitladen

Wenn man die Javadoc und die Sourcen immer mitladen will, kann man diesen Aussschnitt in die pom.xml schreiben:

<project>
  [...]
  <build>
    [...]
    <plugins>
      [...]
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <configuration>
          <downloadSources>true</downloadSources>
          <downloadJavadocs>true</downloadJavadocs>
        </configuration>
      </plugin>
      [...]
    </plugins>
    [...]
  </build>
  [...]
</project>

Downloads

Datei:Maven-bins.zip

Ein paar URLs

Repository management best practices

Maven-Proxy

ViewVC: Browser interface for CVS and Subversion

Installation

Installation Instructions

commands

mvn test

Running all tests

mvn test

Running a single test

During development, you may run a single test class repeatedly. To run this through Maven, set the test property to a specific test case.

mvn -Dtest=TestCircle test

The value for the test parameter is the name of the test class (without the extension; mvn will strip off the extension if you accidentally provide one).

You may also use patterns to run a number of tests:

mvn -Dtest=TestCi*le test

And you may use multiple names/patterns, separated by commas:

mvn -Dtest=TestSquare,TestCi*le test

You can also run tests in package:

mvn -Dtest=de.mypackage.*Test test

Running a Set of Methods in a Single Test Class

As of Surefire 2.7.3, you can also run only a subset of the tests in a test class.

NOTE : This feature is supported only for Junit 4.x and TestNG.

You must use the following syntax:

mvn -Dtest=TestCircle#mytest test

You can use patterns too

mvn -Dtest=TestCircle#test* test

As of Surefire 2.12.1, you can select multiple methods (JUnit 4.x only at this time; patches welcome!):

mvn -Dtest=TestCircle#testOne+testTwo test