SlideShare une entreprise Scribd logo
4 – Build automation
Maven
625-1.1 Industrialisation du logiciel
Bachelor en informatique de gestion – 3IGPT/4IGTP
ulysse.rosselet@he-arc.ch
Analyse Conception Production Déploiement
Build automation
• Première étape de l’industrialisation : recréer un artefact de
manière fiable depuis le code source.
• Principe dans le cadre de l’intégration continue: à chaque
changement du code source (commit) on build l’artefact et
on exécute les tests unitaires.
• Ainsi, on s’assure du bon fonctionnement des nouvelles
fonctionnalités et de la non régression
Build tools, récapitulation
Ant
• Ant follows an imperative approach.
Developers have to take care of all build
aspects by themselves. For example, they
have to generate directories for the compiled
code and explicitly handle dependencies
between the individual parts of the build. In
essence, the developers have to implement
the build completely by themselves in a step-
by-step manner.
Maven
• uses a declarative approach.
• For many aspects of the build it predefines conventions
that Maven projects have to abide by.
• Examples :
• the locations where source code and tests are stored,
• the directories for the build results,
• the sequence of the build phases.
• This renders the configuration of a build very easy.
• However, wherever a build deviates from the convention
or where configurations have to be changed, the
developer has to specifically declare this.
• In practice Maven builds are often even more complex
than builds with other tools.
• In any case the sequence of phases of a build has to fit to
the life cycle model of Maven, which defines the different
build phases.
Gradle
• newest approach with regards to Java build
tools.
• combine the best aspects of the imperative and
the declarative approaches.
• As in the case of Maven, with Gradle many
aspects of a build are defined by conventions.
• However, if the conventions do not fit, Gradle
allows the developer to completely deviate from
them and to implement independent processes
with the help of the Gradle DSL or the
programming language Groovy on which Gradle
is based.
- C. Baudet
Convention
Configuration
Principe de maven
Maven
• Basée sur une approche declarative opposée à Ant.
• Les aspects principaux du build sont fixés par des
conventions auxquelles les projets maven doivent se
soumettre.
• Un build standard maven comprend de nombreuses phases.
• Les plugins maven implémentent concrètement les tâches
correspondants à ces phases
Project
Object
Model
• La base dans Maven
• Fichier XML contenant les informations et les détails de configuration
utilisés par Maven pour «builder» le projet
• La plupart de ces valeurs sont définies par défaut, exemples
le dossier de build  target
le dossier source  src/main/java
les sources de test  src/test/java
Super POM
• La POM par défaut de maven
• Toutes les POM étendent la Super POM
 la configuration définie dans la Super POM est héritée par
les POMs de vos projets.
https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
Exercice
• Jetez un oeil à la super pom
Super Pom, extrait
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutpu
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirect
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
minimal POM
• Le minimum à redéfinir pour un projet :
groupId, artifactId et version
• Définissent le nom complet de l’artefact sous la forme
<groupId>:<artifactId>:<version>
• Avec cet exemple: "com.mycompany.app:my-app:1".
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
</project>
Exercice
• Faites un fork du projet StringCalc sur github
• Clonez-le sur votre PC et
• faites un checkout de la branche minimalpom
• git checkout minimalpom
• tentez de lancer la suite de tests
• Ajoutez les dépendances manquantes
 comment intellij peut-il vous aider?
• Quels problèmes subsitent encore?
Maven commentaires
• Très conservateur au niveau des configurations
• P.ex par défaut, java 1.5 alors que 1.8 est la version courante
•  nécessité d’écraser un grand nombres des conventions par
défaut.
Maven project object model
(pom.xml) typique pour java 8
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId> com.mycompany.app </groupId>
<artifactId> my-app </artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Maven project object model
(pom.xml) typique pour java 8
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
Maven project object model
(pom.xml) typique pour java 8
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Maven phases de build
Maven standard directory
layout
src/main/java Application/Library sources
src/main/resources Application/Library resources
src/main/filters Resource filter files
src/main/webapp Web application sources
src/test/java Test sources
src/test/resources Test resources
src/test/filters Test resource filter files
src/it Integration Tests (primarily for plugins)
src/assembly Assembly descriptors
src/site Site
LICENSE.txt Project's license
NOTICE.txt Notices and attributions required by libraries that the
project depends on
README.txt Project's readme
https://maven.apache.org/guides/introduction/introduction-to-the-
standard-directory-layout.html
- C. Baudet
pom.xml
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
Maven dépendances
- C. Baudet
Machine avec
Maven
Dépôts de librairies
sur le web
Dépôts de librairies
de votre institution
http://repo1.maven.org/
Votre dépôt
local
Pour les
ressources
institutionnelles
- Archiva
- Nexus
- Artifactory
Maven dépendances

Contenu connexe

Similaire à SLIDES-625.1.1-IDL-4-build tools maven.pdf

Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)
Celinio Fernandes
 
Maven et industrialisation du logiciel
Maven et industrialisation du logicielMaven et industrialisation du logiciel
Maven et industrialisation du logiciel
ENSET, Université Hassan II Casablanca
 
Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)
Celinio Fernandes
 
Methodologie projet
Methodologie projet Methodologie projet
Methodologie projet
Benjamin ACHAB
 
Soiree Maven 2
Soiree Maven 2Soiree Maven 2
Soiree Maven 2
Laurent RUAUD
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven
Arnaud Héritier
 
Qualité Logiciel - Outils Open Source pour Java et Web
Qualité Logiciel - Outils Open Source pour Java et WebQualité Logiciel - Outils Open Source pour Java et Web
Qualité Logiciel - Outils Open Source pour Java et Web
Christophe Rochefolle
 
JCertif 2012 : Maven par la pratique
JCertif 2012 : Maven par la pratiqueJCertif 2012 : Maven par la pratique
JCertif 2012 : Maven par la pratique
Rossi Oddet
 
Cedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure DevopsCedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure Devops
AZUG FR
 
Cedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure DevopsCedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure Devops
FactoVia
 
Migrer de Jenkins vers Azure DevOps les Builds Java
Migrer de Jenkins vers Azure DevOps les Builds JavaMigrer de Jenkins vers Azure DevOps les Builds Java
Migrer de Jenkins vers Azure DevOps les Builds Java
Cédric Leblond
 
Maven
MavenMaven
20080923 04 - Selenium web application testing system
20080923 04 - Selenium web application testing system20080923 04 - Selenium web application testing system
20080923 04 - Selenium web application testing system
LeClubQualiteLogicielle
 
Play Framework
Play FrameworkPlay Framework
Play FrameworkArmaklan
 
20180628 skill value_masterclass_reactnative - v1.3
20180628 skill value_masterclass_reactnative - v1.320180628 skill value_masterclass_reactnative - v1.3
20180628 skill value_masterclass_reactnative - v1.3
Benoit Fillon
 
JavaScript dans l'usine logicielle
JavaScript dans l'usine logicielleJavaScript dans l'usine logicielle
JavaScript dans l'usine logicielle
jollivetc
 

Similaire à SLIDES-625.1.1-IDL-4-build tools maven.pdf (20)

Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)Presentation of GWT 2.4 (PDF version)
Presentation of GWT 2.4 (PDF version)
 
Maven et industrialisation du logiciel
Maven et industrialisation du logicielMaven et industrialisation du logiciel
Maven et industrialisation du logiciel
 
Gradle_BordeauxJUG
Gradle_BordeauxJUGGradle_BordeauxJUG
Gradle_BordeauxJUG
 
Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)Presentation of GWT 2.4 (PowerPoint version)
Presentation of GWT 2.4 (PowerPoint version)
 
Methodologie projet
Methodologie projet Methodologie projet
Methodologie projet
 
Soiree Maven 2
Soiree Maven 2Soiree Maven 2
Soiree Maven 2
 
20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven20090615 - Ch'ti JUG - Apache Maven
20090615 - Ch'ti JUG - Apache Maven
 
Qualité Logiciel - Outils Open Source pour Java et Web
Qualité Logiciel - Outils Open Source pour Java et WebQualité Logiciel - Outils Open Source pour Java et Web
Qualité Logiciel - Outils Open Source pour Java et Web
 
JCertif 2012 : Maven par la pratique
JCertif 2012 : Maven par la pratiqueJCertif 2012 : Maven par la pratique
JCertif 2012 : Maven par la pratique
 
Cedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure DevopsCedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure Devops
 
Cedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure DevopsCedric leblond migrer jenkins AWS vers Azure Devops
Cedric leblond migrer jenkins AWS vers Azure Devops
 
Migrer de Jenkins vers Azure DevOps les Builds Java
Migrer de Jenkins vers Azure DevOps les Builds JavaMigrer de Jenkins vers Azure DevOps les Builds Java
Migrer de Jenkins vers Azure DevOps les Builds Java
 
Sonar-Hodson-Maven
Sonar-Hodson-MavenSonar-Hodson-Maven
Sonar-Hodson-Maven
 
Maven
MavenMaven
Maven
 
20080923 04 - Selenium web application testing system
20080923 04 - Selenium web application testing system20080923 04 - Selenium web application testing system
20080923 04 - Selenium web application testing system
 
Play Framework
Play FrameworkPlay Framework
Play Framework
 
gradle_nantesjug
gradle_nantesjuggradle_nantesjug
gradle_nantesjug
 
20180628 skill value_masterclass_reactnative - v1.3
20180628 skill value_masterclass_reactnative - v1.320180628 skill value_masterclass_reactnative - v1.3
20180628 skill value_masterclass_reactnative - v1.3
 
Gradle_ToulouseJUG
Gradle_ToulouseJUGGradle_ToulouseJUG
Gradle_ToulouseJUG
 
JavaScript dans l'usine logicielle
JavaScript dans l'usine logicielleJavaScript dans l'usine logicielle
JavaScript dans l'usine logicielle
 

SLIDES-625.1.1-IDL-4-build tools maven.pdf