Rapport d'exécution des tests dans maven Utilisation et configuration des plugins

Utilisation des plugins

Introduction

Invoquer un plugin

Commande de base: mvn groupId:artifactId:[version:]goal

nono@osquare:~/enseign/maven/hello$ mvn org.apache.maven.plugins:maven-javadoc-plugin:javadoc
[INFO] Scanning for projects...
[INFO] ----------------------------------------------------------------------------
[INFO] Building Maven Quick Start Archetype
[INFO]    task-segment: [org.apache.maven.plugins:maven-javadoc-plugin:javadoc]
[INFO] ----------------------------------------------------------------------------
[INFO] Preparing javadoc:javadoc
....
[INFO] [javadoc:javadoc]
Loading source file /home/nono/enseign/maven/hello/src/main/java/fr/norsys/App.java...
Constructing Javadoc information...
Standard Doclet version 1.5.0_06
Building tree for all the packages and classes...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//App.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//package-frame.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//package-summary.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//package-tree.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/constant-values.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//class-use/App.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/fr/norsys//package-use.html...
Building index for all the packages and classes...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/overview-tree.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/index-all.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/deprecated-list.html...
Building index for all classes...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/allclasses-frame.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/allclasses-noframe.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/index.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/help-doc.html...
Generating /home/nono/enseign/maven/hello/target/site/apidocs/stylesheet.css...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7 seconds
[INFO] Finished at: Tue Jun 27 11:12:02 CEST 2006
[INFO] Final Memory: 6M/11M
[INFO] ------------------------------------------------------------------------


Utilisation de préfixes

Pour simplifier l'utilisation des plugins, ceux-ci peuvent associer à un préfixe. La commande devient donc simplement: mvn prefix:goal

Par convention, le préfixe d'un plugin est déduit de son nom: maven-toto-plugin ----> préfixe: toto

Cette information est stockée dans la méta-information (maven-metadata.xml) asociée au groupe du plugin dans le référentiel dont il provient. Par exemple:

nono@osquare:~/enseign/maven/hello$ cat /var/lib/m2/fr/lifl/maven-metadata.xml
<?xml version="1.0" encoding="UTF-8"?><metadata>
  <plugins>
    <plugin>
      <name>Maven FIDL Plugin</name>
      <prefix>fidl</prefix>
      <artifactId>maven-fidl-plugin</artifactId>
    </plugin>
  </plugins>
</metadata>maven-fidl-plugin<

Ce fichier indique que le préfixe fidl est associé à l'artefact maven-fidl-plugin dans le groupe fr.lifl

Ce lien entre préfixe et plugin peut-être configuré encore plus finement:  

Invocation automatique et configuration

Liaison d'un plugin à une phase

Chaque plugin (ou plutôt chaque but) peut être lié à une phase du cycle de vie de la construction d'artefacts:

Le plugin est alors automatiquement invoqué lors de l'exécution de la phase choisie.

Configuration de l'exécution d'un plugin

La configuration des plugins s'effectue dans le POM du projet qui l'utilise:  

Dans tous les cas, les informations de configuration sont regroupées dans un tag XML:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerVersion>1.4</compilerVersion> <!-- don't use 1.5 just yet -->
          <source>1.4</source> <!-- necessary to enable assertions -->
          <target>1.4</target> <!-- don't make it backward compatible -->
          <debug>true</debug>
          <showDeprecation>true</showDeprecation>
          <showWarnings>true</showWarnings>
          <optimize>false</optimize>
              <!-- to make debugging possible;
                   should be set to true for a release with a profile -->
        </configuration>
      </plugin>
      [...]
    </plugins>
  </build>


ou pour une configuration par exécution:

[...]
<project>
  [...]
      <plugin>
        [...]
        <executions>
          <execution>
          [...]
            <configuration>
              configuration for this execution of the plugin
            </configuration>
          [...]
          </execution>
        </executions>
        [...]
        <configuration>
          configuration for all executions of the plugin
        </configuration>
      </plugin>
  [...]
</project>

voir syntaxe et propriétés des mojo.

index

Footnotes:  [1]  En attendant l'utilisation des annotations de java5.0...