0% ont trouvé ce document utile (0 vote)
20 vues48 pages

Maven

Ce document présente Apache Maven 2, un outil de gestion de projet pour Java, en détaillant ses motivations, son installation, sa structure de projet, et son cycle de vie. Il explique également le modèle de projet POM, la gestion des dépendances, et les plugins disponibles. Enfin, il aborde la configuration des plugins et l'utilisation des profils pour améliorer la portabilité des projets.

Transféré par

youbikm
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
20 vues48 pages

Maven

Ce document présente Apache Maven 2, un outil de gestion de projet pour Java, en détaillant ses motivations, son installation, sa structure de projet, et son cycle de vie. Il explique également le modèle de projet POM, la gestion des dépendances, et les plugins disponibles. Enfin, il aborde la configuration des plugins et l'utilisation des profils pour améliorer la portabilité des projets.

Transféré par

youbikm
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats PDF, TXT ou lisez en ligne sur Scribd

http://membres-liglab.imag.

fr/donsez/cours

Apache Maven 2

Didier DONSEZ
Université Joseph Fourier – Grenoble 1
PolyTech’Grenoble – LIG/ADELE
[email protected]
[email protected]
[email protected]
29/03/2010

Licence
 Cette présentation est couverte
par le contrat Creative Commons By NC ND
 http://creativecommons.org/licenses/by-nc-nd/2.0/fr/
Didier Donsez, 2007-2010, Maven

2
29/03/2010

Au sommaire
 Motivation
 Installation
 Cycle de vie
 Structure d’un projet Maven
 Plugins Maven
 Développement d’un plugin
 Bibliographie et Webographie
Didier Donsez, 2007-2010, Maven

3
29/03/2010

Motivations
 Rappel sur ANT
 Remplaçant de make (pour les développements Java)
 NAnt pour .NET
 Séquenceur de taches (regroupées en cible)
 Graphe de dépendance de « cibles »
 Très grand nombre de taches développées
 Défaut
 Pas de structure « standard » de projet
 Pas de cycle de vie « standard » d’un projet
Didier Donsez, 2007-2010, Maven

 Pas de métadonnées « standard » sur les projets


 scm, website, ML, …
 Pas de séparation de préoccupation
 Libs externes à récupérer pour le projet et pour les tâches
 problème de la MAJ des versions
4
29/03/2010

Motivations de Maven
 Modèle abstrait de projet (POM)
 Orienté objet, héritage
 Séparation de préoccupations
 Cycle de vie standard
 Séquencement d’états (goal) standards
 Action des plugins en fonction des états
 Structure « standard » de projet
 Nommage standard des variables (src.dir, …)
 Gestion automatique des dépendances avec d’autres projets
 Chargement des MAJ
 Dépôts des projets
Didier Donsez, 2007-2010, Maven

 publiques ou privés, local ou distants


 caching et proxy
 Extensible via l’ajout des plugins
 Eux même des projets Maven

5
29/03/2010

Installation
 Télécharger la distribution binaire
 http://maven.apache.org
 Dézipper dans un répertoire
 Positionner les variables d’environnement
Évites d’être
 set JAVA_HOME=c:\j2sdk1.x.y
ennuyer par des
 set MAVEN_HOME=c:\maven-2.z.w VM « parasites »
 set PATH=%JAVA_HOME%\bin;%MAVEN_HOME%\bin
 mvn –version
 mvn --help
 (éventuellement) Configurer ~/.m2/settings.xml
Didier Donsez, 2007-2010, Maven

 repositories, plugins repositories, proxies, …

 Intégration à votre IDE (Eclipse, NetBeans, IDEA, …)


 http://m2eclipse.codehaus.org/, http://mevenide.codehaus.org …

6
29/03/2010

mvn --help
usage: mvn [options] [<goal(s)>] [<phase(s)>]
Options:
-q,--quiet Quiet output - only show errors
-C,--strict-checksums Fail the build if checksums don't match
-c,--lax-checksums Warn if checksums don't match
-P,--activate-profiles Comma-delimited list of profiles to activate
-ff,--fail-fast Stop at first failure in reactorized builds
-fae,--fail-at-end Only fail the build afterwards; allow all non-impacted builds to continue
-B,--batch-mode Run in non-interactive (batch) mode
-fn,--fail-never NEVER fail the build, regardless of project result
-up,--update-plugins Synonym for cpu
-N,--non-recursive Do not recurse into sub-projects
-npr,--no-plugin-registry Don't use ~/.m2/plugin-registry.xml for plugin versions
-U,--update-snapshots Forces a check for updated releases and snapshots on remote repositories
-cpu,--check-plugin-updates Force upToDate check for any relevantregistered plugins
-npu,--no-plugin-updates Suppress upToDate check for any relevant registered plugins
Didier Donsez, 2007-2010, Maven

-D,--define Define a system property


-X,--debug Produce execution debug output
-e,--errors Produce execution error messages
-f,--file Force the use of an alternate POM file.
-h,--help Display help information
-o,--offline Work offline
-r,--reactor Execute goals for project found in the reactor
-s,--settings Alternate path for the user settings file
-v,--version Display version information
7
29/03/2010

Le modèle de projet
(POM pour Project Object Model)
 Description d’un projet indépendante des actions à accomplir
 Orienté objet  héritage du modèle
 Exemple
<project> Identifiant (unique) du projet :
<modelVersion>4.0.0</modelVersion> Identifiant de l’artifact produit
<groupId>com.mycompany.app</groupId> type du projet:
<artifactId>my-app</artifactId> pom, jar, war, ear, bundle, …
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging> dépendances du projet envers
<dependencies> d’autres projets (artifact)
constitue le $CLASSPATH
<dependency>
id d’une dépendance
<groupId>junit</groupId>
version peut être un intervalle
<artifactId>junit</artifactId>
Didier Donsez, 2007-2010, Maven

<version>3.8.1</version> portée de la dépendance par rapport au cycle


de vie (compile, provided, runtime, test)
<scope>test</scope>
</dependency>
</dependencies>
la suite bientôt …

</project>
8
29/03/2010

Dependances
 Concerne les artifacts comme les plugins
 Résolution transitive
<project> …
<groupId>com.mycompany.app</groupId> mybundle-1.0.0
<artifactId>mybundle</artifactId>
<version>1.0.0</version> … dependency
<dependencies> declaration
<dependency>
<groupId>org.osgi</groupId> compendium-4.0.0
<artifactId>compendium</artifactId>
<version>4.0.0</version> transitive
</dependency> resolution
Didier Donsez, 2007-2010, Maven

</dependencies>
… </project>
core-4.0.0

 Sert à constituer le CLASSPATH


 Pour la compilation, pour les tests, pour l’exécution
9
29/03/2010

Portée des dépendances


 5 portées possibles par rapport aux classpaths du projet
 compile (défaut)
 Disponible dans tous les classpaths
 Transistive vers les projets dépendants
 provided
 compilation and test classpaths
 Not transitive.
 runtime
 runtime and test classpaths.
 test
 test compilation and execution phases.
 system
 similar to provided but the artifact is always available and is not looked up in a repository.
 import
 only used on a dependency of type pom in the <dependencyManagement> section.
Didier Donsez, 2007-2010, Maven

 Portée transistive

10
29/03/2010

Structure « standard » d’un projet

mvn package
Didier Donsez, 2007-2010, Maven

Remarque: Maven ajoute le


POM à l’artifact packagé

Remarque: Maven crée un répertoire de travail


${basedir}/target commun à tous les plugins 13
29/03/2010

Cycle de vie (par défaut) d’un projet


 Séquence de 21 phases

Code
Source validate generate-test-sources pre-integration-test
initialize process-test-sources integration-test
generate-test-resources post-integration-test
generate-sources
process-test-resources
process-sources
test-compile
generate-resources
Didier Donsez, 2007-2010, Maven

test
process-resources verify
compile install
process-classes package deploy

artifact 14
29/03/2010

Phases et Buts (goals)


 A chaque phase est associé un ou plusieurs buts
d’un ou de plusieurs plugins
surefire:test
test

package jar:jar

 Remarque
 mvn resources:resources compiler:compile resources:testResources compiler:testCompile
Didier Donsez, 2007-2010, Maven

surefire:test jar:jar est équivalent à mvn package


 D’autre cycles de vie ont été définis
 clean = pre-clean  clean  post-clean
 site = pre-site  site  post-site  site-deploy
 …

15
29/03/2010

Rappel
Numérotation des versions
 Schéma
<major>.<mini>[.<micro>][-<qualifier>[-<buildnumber>]]
 Incrément
 Major : changement majeur
 pas de retro-compatibilité (descendante) garantie
 Mini : ajouts fonctionnels
 retro-compatibilité garantie
 Micro : maintenance corrective (bug fix)
 Qualificateurs
 SNAPSHOT (Maven) : version en évolution
 alpha1 : version alpha (très instable et incomplète)
 beta1, b1, b2 : version beta (instable)
 rc1, rc2 : release candidate
 m1, m2 : milestone
 ea : early access
 20081014123459001 : date du build
 jdk5 : dépendance avec une arch, un os, un langage
 Ordre sur les versions
Didier Donsez, 2007-2010, Maven

 Différent de l’ordre lexicographique


 1.1.1 < 1.1.2 < 1.2.2
 1.1.1-SNAPSHOT < 1.1.1
 1.1.1-alpha1 < 1.1.1-alpha2 < 1.1.1-b1 < 1.1.1-rc1 < 1.1.1-rc2 < 1.1.1
 Remarque (parfois)
 <mini> pair : release stable
 <mini> impair : release instable

17
29/03/2010

Versionnement
 Snapshot
 A snapshot in Maven is an artifact which has been prepared using
the most recent sources available. … Specifying a snapshot
version for a dependency means that Maven will look for new
versions of that dependency without you having to manually specify
a new version.
 mvn -U command line option to force the search for updates.

 Dépendances
Didier Donsez, 2007-2010, Maven

 Spécification d’intervalles de versions


<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
<version>[1.1,)</version>
</dependency>

19
29/03/2010

Quelques plugins usuels


 Core
 clean, compiler, deploy, install, resources, site, surefire, verifier
 Packaging
 ear, ejb, jar, rar, war, bundle (OSGi)
 Reporting
 changelog, changes, checkstyle, clover, doap, docck, javadoc, jxr,
pmd, project-info-reports, surefire-report
 Tools
 ant, antrun, archetype, assembly, dependency, enforcer, gpg, help,
invoker, one (interop Maven 1), patch, plugin, release, remote-
resource, repository, scm
Didier Donsez, 2007-2010, Maven

 IDEs
 eclipse, netbeans, idea
 Autres
 exec, jdepend, castor, cargo, jetty, native, sql, taglist, javacc, obr …

 http://maven.apache.org/plugins/, http://mojo.codehaus.org/plugins.html, …
21
29/03/2010

Configuration des plugins


 Passage de paramètres autre que ceux définis par défaut
 Exemple
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
Didier Donsez, 2007-2010, Maven

<mainClass>${artifactId}.Main</mainClass>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>

22
29/03/2010

Profils
 Motivation
 Améliorer la portabilité des projets par rapport aux
environnements
 Différents JVM, versions de Java, serveurs JEE, SGBD,
développement versus production
 Créer des variations (=profils) de projets
 Elément <profile> du build
 Contient les variations de plugins et entre les plugins
 Activation du profil
Didier Donsez, 2007-2010, Maven

 Profil par défaut


 En fonction des propriétés (systèmes, version JDK, …)
 Par son identifiant
 mvn --activate-profiles felix,equinox clean install
24
29/03/2010

Organisation hiérarchique de projets


 Motivations
 Organiser le développement en sous-projets
 Avec N niveaux (N>=1)
 Méthode
 Création d’un super POM (de type pom) par niveau
 Regroupe les plugins/goals communs du même niveau
 Les sous-projets (appelé modules) héritent de ce super pom
 Exemple
Didier Donsez, 2007-2010, Maven

 Commande
 mvn --reactor clean install
 Pour la construction globale

26
29/03/2010

Documentation Web d’un projet


 Transforme plusieurs formats de documentation
 XDOC, APT (Almost Plain Text), FML (FAQ ML), DocBook Simple, Twiki,
Confluence

 La documentation source peut contenir des variables du


projet ($project.name, $reports, …)

mvn site:site
Didier Donsez, 2007-2010, Maven

27
29/03/2010

Dépôts de projets
 Local ~/.m2/repository
 Projets (dont artifacts) installés
localement
 mvn install
 mvn install:install-file
 Caches des projets (artifacts) téléchargés
depuis les dépots distants
 Listés dans les POM et settings.xml
 Distants
 Dépôts d’entreprise
Cache de dépôts
Didier Donsez, 2007-2010, Maven

 Dépôts publiques
 Structure
 Nommage hiérarchique
 ${groupId}.replace('.','/') / ${articfactId} / ${version}

28
29/03/2010

Dépôts publiques
 Les principaux
 Apache Maven Central
 http://repo1.maven.org/maven2/
 Plus de 20000 artifacts décrits (en 2007)
 Tous en licence ASL v2

 CodeHaus
 http://www.codehaus.org
 Dependance vers d’autres licences (BSD, …)
Didier Donsez, 2007-2010, Maven

29
29/03/2010

Recherche des dépendances

Web Servers
project.xml (POM)
Download artifact
1 Get dependencies
3
Maven core
HTTP
Remote
Repositories
2 4 (listed in
Local ~/.m2/settings.xml)
Checks if Repository Save artifact in local
Didier Donsez, 2007-2010, Maven

artifact exists repository


in local repo. ~/.m2/repository

JVM 1 JVM 2

R1: La mise à jour du dépôt local est journalière (sauf si mvn –U)
R2: Les plugins sont recherchés et mis à jour de la même façon

30
D’après Vincent Massol
29/03/2010

Substitution de variables à la construction


 Motivations
 Instancier les valeurs des ressources lors de la phase process-
resources
 Exemple de POM
… <build>
<filters>
<filter>src/main/filters/filter.properties</filter>
</filters> # src/main/filters/filter.properties
<resources> my.filter.value=Hello !
<resource>
Didier Donsez, 2007-2010, Maven

<directory>src/main/resources</directory>
<filtering>true</filtering>
# src/main/resources/application.properties
</resource>
message=${my.filter.value}
</resources> application.name=${project.name}
</build> application.version=${project.version}
31
29/03/2010

Archetype
 Construction initial d’un projet Maven
 En fonction d’un type de projet T
 T= quickstart, archetype, bundles, j2ee-simple, marmalade-
mojo, mojo, plugin, plugin-site, portlet, profiles, simple, site,
site-simple, webapp, …
 Exemple
 mvn archetype:create
mode interactif
 mvn archetype:create
-DgroupId=demo.maven
Didier Donsez, 2007-2010, Maven

-DartifactId=hello
-Dversion=0.1.0-SNAPSHOT
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-quickstart
32
29/03/2010

Archetypes personnalisés
 Possibilité de créer ses propres archetypes
  de zero
mvn archetype:create
-DarchetypeGroupId=org.apache.maven.archetypes
-DarchetypeArtifactId=maven-archetype-archetype
-DgroupId=com.mycompany
-DartifactId=my-archetype

  depuis un archetype existant


 Développement
 Basé sur des templates Velocity (http://velocity.apache.org/)
Didier Donsez, 2007-2010, Maven

33
29/03/2010

Développement de plugins
 Plugin = { <goal,MOJO> }
 MOJO = Maven POJO
 Annotations XDocLet

 Langages
 Java et Groovy (pour le scripting)
 D’autres possibles …

Déploiement
Didier Donsez, 2007-2010, Maven


 Artifact Maven
 Utilise les mécanismes de déploiement (version, dépendances, …)
 Dépôts de plugins
 http://maven.apache.org/plugins/, http://repository.codehaus.org/

34
29/03/2010

Développement de plugins
Exemple (i)
package sample.plugin;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
/** phase et but durant laquelle
* Says "Hi" to the user. execute() est appelé
* @goal sayhi
* @phase compile
*/ paramètre renseigné dans
public class GreetingMojo extends AbstractMojo { <configuration>
/** The greeting to display.
* @parameter alias="message" expression="Hello, world (from ${project.groupId}:${project.artifactId})" */
private String greeting;
Integer, …, String, List, Properties,
Map, Object, File, URL, …
/** The classpath.
Didier Donsez, 2007-2010, Maven

* @parameter expression="${project.compileClasspathElements}"
* @required
* @readonly */ paramètre issue du pom
private List classpathElements;

public void execute() throws MojoExecutionException {


getLog().info(greeting);
getLog().info("Project classpath: " + classpathElements().toString().replace( ',', ';' ));
}} 35
29/03/2010

Développement de plugins
Exemple (ii)
 Dans le POM
<build>
<plugins>
<plugin>
<groupId>sample.plugin</groupId>
<artifactId>maven-hello-plugin</artifactId>
<configuration>
<message>Welcome</message>
</configuration>
</plugin>
Didier Donsez, 2007-2010, Maven

</plugins>
</build>
 Exécution
mvn sample.plugin:maven-hello-plugin:sayhi

36
29/03/2010

Plugins et Cycles de vie


 MOJO attaché à une phase du cycle de vie
 @nnotations doclet

 Cycles de vie personnalisés


 Surcharge de META-INF/plexus/components.xml,
Didier Donsez, 2007-2010, Maven

37
29/03/2010

Appel de tâches ANT dans un projet


Maven
 Motivations
 récupération de projets existants avant connversion
 Exécution de taches patrimoniales n’ayant pas de plugins équivalents
 Remarque: pensez à utiliser la définition de Macro ANT !
 Exemple avec le plugin org.apache.maven.plugins:maven-antrun-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>generate-sources</phase>
<configuration>
<tasks unless="maven.test.skip">
<!-- Place any ant task here. You can add anything
you can add between <target> and </target> in a build.xml.-->
<echo message="To skip me, just call mvn -Dmaven.test.skip=true"/>
<exec dir="${basedir}"
Didier Donsez, 2007-2010, Maven

executable="${basedir}/src/main/sh/do-something.sh" failonerror="true">
<arg line="arg1 arg2 arg3 arg4" />
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin> 38
29/03/2010

Conversion d’un projet ANT en projet


Maven
 2 possibilités pour la structure du projet
 Réorganiser (manuellement, projet ANT si plusieurs
projets)
 src  src/main/java, src/test/java, doc  src/site
 classes  target/classes, build  target, …
 Configurer les paramètres par défaut du POM
en fonction de la structure du projet ANT

Définir les dépendances


Didier Donsez, 2007-2010, Maven

 en fonction du <classpath …>

39
29/03/2010

Antlib for Maven


 Taches Maven pour projet ANT
 Manipulation d’ artifacts depuis un projet Ant
 Gestion (transitive) des dépendances
 scope recognition and SNAPSHOT handling

 Déploiment des artifacts vers un dépot Maven


 Analyse d’un pom.xml
 Exemple
<artifact:dependencies pathId="dependency.classpath">
<dependency groupId="javax.servlet" artifactId="servlet-api"
version="2.4" scope="provided" />

Didier Donsez, 2007-2010, Maven

</artifact:dependencies>
<javac ...>
<classpath refid="dependency.classpath" />
...
</javac>

40
29/03/2010

Maven et autres langages


 Maven est plutôt orienté vers des projets Java

 Projets pour d’autres environnements et langages


 .NET, …
 JNI, C, C++, C#, PHP, JavaScript, GWT, Basic, ..

 Structure du projet
 src/main/java
 src/main/c
 src/main/cpp
 src/main/cs
 src/main/php
Didier Donsez, 2007-2010, Maven

 src/main/vb
 …
 Plugins
 maven-antrun-plugin (org.apache.maven.plugins:)
 pour la récupération de tâches Ant patrimoniales
 native-maven-plugin (org.codehaus.mojo:)
42
29/03/2010

Misc
 Maven SCM
 Plugin offrant une API commun vers les principaux SCM
 Commandes
 Changelog - command to show the source code revisions
 Checkin - command for commiting changes
 Checkout - command for getting the source code
 Diff - command for showing the difference of the working copy with the remote ones
 Edit - command for starting edit on the working copy
 Status - command for showing the scm status of the working copy
 Tag - command for tagging the certain revision
 UnEdit - command for to stop editing the working copy
 Update - command for updating the working with the latest changes
 Validate - validates the scm information on the pom
 Supported SCM
 Subversion, CVS, Starteam, Clearcase, Perforce, bazaar
 Maven Continuum
 continuous integration (JEE-based) server for building Java based projects.
 Schedulable projects: Maven 1, Maven 2, Ant, Shell scripts
Notifications : Mail and IM (IRC, Jabber, MSN)
Didier Donsez, 2007-2010, Maven

 Maven Archiva
 Repository manager (search, security, reporting, …)
 Maven Wagon
 Outil de transfert des artifacts vers des dépots (distants ou locaux)
 File, HTTP, HTTP lightweight, FTP, SSH/SCP, WebDAV, SCM

43
29/03/2010

Misc
 Apache Ivy
 Gestionnaire de dépendances (pour projet Ant)
 Sous gestionnaire pour des dépôts Maven (locaux ou distants)
Didier Donsez, 2007-2010, Maven

44
29/03/2010

M2Eclipse
Plugin Eclipse pour Maven
 Création de projets
 Wizard, Archetypes
 Edition du POM
 Affichage graphique
 Recherche de dépendances
 Depuis les dépôts local et distants
Ajout des dépendances du POM
au .classpath
org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER
Didier Donsez, 2007-2010, Maven

 Exécution des principales phases : clean, test, install, …


 Livre en ligne
 http://www.sonatype.com/m2eclipse/documentation/download-book?file=books/m2eclipse-book.pdf

45
29/03/2010

M2Eclipse
Plugin Eclipse pour Maven
Didier Donsez, 2007-2010, Maven

46
29/03/2010

Maven Continuum
http://maven.apache.org/continuum/

 continuous integration (JEE-based)


server for building Java based projects.
 Schedulable projects: Maven 1, Maven 2,
Ant, Shell scripts
 Notifications : Mail and IM (IRC, Jabber,

MSN)
 Release management

 SCM support
Didier Donsez, 2007-2010, Maven

 CVS, Subversion, Clearcase, Perforce, Starteam, Visual


Source Safe, CM Synergy, Bazaar, Mercurial
 External access with XMLRPC

47
29/03/2010

Maven Continuum
 Console
Didier Donsez, 2007-2010, Maven

48
29/03/2010

Divers
 Recherche d’artifacts
 http://www.mvnrepository.com/
Didier Donsez, 2007-2010, Maven

49
29/03/2010

Misc
 Tree Surgeon (Maven pour .NET ?)
 http://confluence.public.thoughtworks.org/display/TREE/Tree+Surgeon
 « Tree Surgeon est un outil Open Source édité par la
société de Martin Fowler Thoughtworks. "It is a tool that
automates the process of establishing a directory
structure with source code stubs and supporting
infrastructure in a consistent manner. (...) It supports
tools like NAnt and NUnit by generating build files and
unit tests as part of the automated process. . Même si
Didier Donsez, 2007-2010, Maven

Tree Surgeon (au nom peu invocateur) est loin


d'atteindre le niveau fonctionnel de son homologue Java
Maven, il constitue une excellente base pour
industrialiser la génération de squelettes de projets
.NET. »
50
29/03/2010

Good & Best Practices


 Beginners
 KISS (Keep It Simple, Stupid)
 Start from scractch
 No Copy/Paste
 Use only what you need
 Filtering, Modules, Profiles, …
 Bad practices
 Ignore maven conventions
 Different versions in sub modules
Didier Donsez, 2007-2010, Maven

 Too many inheritance levels


 AntRun (OK for integration test)
 Plugins without versions
 …

From Arnaud Heritier 51


29/03/2010

Maven 3.x
 Any-source POM (json, groovy, …)
 Versionless parent elements
 Mixin : a composition of POMs
 Better IDE integration
 Error reporting
 Codes d’erreur commune
 Lifecycle extension points
 Plugin extension points
 example: war extends jar
 Incremental build support
 Queryable lifecycle
 comportement en fonction du lifecycle calculé au démarrage
 Extensible reporting
Didier Donsez, 2007-2010, Maven

 Continious integration (sonar, …)


 New tools
 tycho : OSGi, Eclipse
 Integration continu
 Transféré vers Eclipse ?
 mvnsh : shell (performance)
 New IoD : Guice (annotation ?)
From Arnaud Heritier 52
29/03/2010

Bibliographie et Webographie
 Web
 Site Maven, http://maven.apache.org
 Exemples et exercices
 http://www-adele.imag.fr/users/Didier.Donsez/cours/tpmvn

 Complément
 http://www-adele.imag.fr/users/Didier.Donsez/cours/coursjavaoutil.pdf
Didier Donsez, 2007-2010, Maven

53
29/03/2010

Bibliographie et Webographie
http://maven.apache.org/articles.html
 Ouvrages
 Maven: The Definitive Guide
 http://www.sonatype.com/book/maven-user-guide.pdf
 En français http://www.maven-definitive-guide.fr/
 John Casey, Vincent Massol, Brett Porter, Carlos Sanchez, Jason
van Zyl, Better Builds with Maven, Publisher Mergere Library Press,
March 2006
 (PDF gratuit en ligne)
 Vraiment bien, mais c’est préférable de connaître Maven auparavant !
 Vincent Massol, Tim O'Brien, Maven: A Developer's Notebook,
Didier Donsez, 2007-2010, Maven

Publisher O'Reilly, July 2005


 Une FAQ en francais
 http://java.developpez.com/faq/maven/
 Livre M2Eclipse en ligne
 http://www.sonatype.com/m2eclipse/documentation/download-book?file=books/m2eclipse-book.pdf

54
29/03/2010

Exercice Développement d’un plugin


 Développement d’un plugin pour Velocity
 et DVSL (Declarative Velocity Style Language)
 Questions
 A quelles phases peut être appliqué ce plugin ?
 …
Didier Donsez, 2007-2010, Maven

55
29/03/2010

Rappel sur Apache Velocity


 Langage de templates (VTL)
 Syntaxe proche des macros CPP
 Macros #set, #foreach() ... #end, #if () …#elseif () …#else …#end, #include(…), #parse(…)
 DVSL (Declarative Velocity Style Language) #match() ... #end
 Variables $var ou ${var}
 Usage
 Génération de pages Web
 Génération de codes sources (generative programming), …
 Exemple VTL
// generated at $date
public static void main(String [] args) {
package ${pkgName};
Velocity.init();
public interface ${itfName}MBean {
VelocityContext vc = new VelocityContext();
#foreach ($attribute in ${attributesList})
vc.put("date", new Date());
/** setter for the attribute ${attribute} */
vc.put("itfName", "Config"); …
Didier Donsez, 2007-2010, Maven

public void set${attribute}(String new${attribute});


Template template
/** getter for the attribute ${attribute} */
= Velocity.getTemplate(args[0]);
public String get${attribute}();
OutputStreamWriter osw =
#end
new StringWriter(System.out);
/** reset all the attributes */
template.merge(vc, osw);
public void reset();
}
}
56

Vous aimerez peut-être aussi