Temario detallado‎ > ‎1: Introducción a UI‎ > ‎Maven‎ > ‎

Maven To Be Refactored

Acá rejuntamos apuntes e info que teníamos cada uno dando vuelta por ahí y que se podrían incorporar al apunte blah.

Manejando dependencias no mavenizadas

Sometimes we need to use thirdparty libraries that are not mavenized. Either they aren't in maven central repository or they are gemalto internal dependencies for projects that don't use maven as scm tool (maybe they are using ant, or something like that).
As maven resolves all of our project's dependencies automatically through maven repositories, we need to make them available as a maven artifact.
This can be done in two ways:

  • manually by executing a maven goal
  • through artifactory UI

Manually Deploy File

by executing a special maven goal for deploying a jar file into a maven repository

'mvn deploy:deploy-file'

is the goal we use make not-mavenized libraries available to maven

You need to specify some values for parameters, like, groupId, artifactId, etc. See below a list of examples

Template for deploying to our repository

-Durl="dav:" -DrepositoryId=releases

Here it's an example command:

mvn deploy:deploy-file -DgroupId=GROUP -DartifactId=ARTIFACT -Dversion=VERSION -Dpackaging=jar -Dfile="PATH_TO_JAR" -Durl="dav:" -DrepositoryId=gemalto-uxp-releases
You need to replace GROUP, ARTIFACT, VERSION and PATH_TO_JAR with your own values.

Deploy File Through Artifactory UI

//TODO: mostrar ejemplo de como hacer deploy por web


mvn release:prepare

It does the following tasks:

    • Checks that your local source code does not have any modifications.
    • Checks that your pom.xml has a "XX-SNAPSHOT" version.
    • Checks that your pom.xml doesn't have dependencies to SNAPSHOTS versions.
    • Writes a release.properties file with details of what it is doing.
    • Modifies the pom.xml to the release version. (removes the "-SNAPSHOT")
    • Does a build as far as "package" in order to assure itself that it's changes have not broken the build.
    • Commits the modified pom.xml files to SCM
    • Tags the trunk
    • Modifies the pom.xml to the next snapshot version. (increments the last number of the version and adds a "-SNAPSHOT" ending)
    • Commits the modified pom.xml files to SCM

mvn release:perform

It does the following tasks:

    • Checks out the tagged release into target/checkout
    • Forks a "mvn deploy site-deploy"
    • Removes the release.properties file

Releasing From Eclipse (standard way for releasing)

Select the project you want to release in the "Project" view or "Package Explorer", depending on the perspective you're using.
And go to the "External Tools" toolbar.

Browse all configurations. You'll have a list like the following…


Here, if you'll have 2 launchers available for releasing:

  • releaseModule: for releasing a regular project
  • releaseParent: for releasing a "parent" project. It's a project with packaging "pom" that has !!
Be careful not to execute the releaseModule over a parent project! See below for more details on these two different launcher for modules and parents

Then, for next releases you'll have the launcher accessible from the dropdown menu, like the following image..


Eclipse allows you to create your own launchers for tools. Launchers can be saved only within your workspace configuration files, or you can change the location to whatever file you want.
We are using this functionality to share many launchers, like the releaseModule, etc, in our team, by saving them in a common project, the SVN/scm/uxp.maven.scm/ project.
So, for releasing you'll need to have checked out this project into your workspace. Eclipse automatically detects all the launchers in that projects and it will make them available for you

Maven Release Commands 'Behind the Hood'

*One-step ~parent~ release command*

mvn -Dusername=${svnUser} -Dpassword=${svnPassword} -N -Darguments=-N --batch-mode install release:prepare release:perform deploy
If it fails, you can rollback the process executing:
mvn -N release:rollback

*One-step ~module~ release command*

mvn -Dusername=${svnUser} -Dpassword=${svnPassword} --batch-mode release:prepare release:perform clean
If it fails, you can rollback the process executing:
mvn release:rollback

Configurando un Proyecto para Release

This Page describes the configuration and structure needed for a project (artifact) to complain with our release process & tools.

Subversion Structure

repo |- folderA |- folderB |- subfolder |- project |- trunk | |- pom.xml | |- src | |- ... |- tags |- branches
You need to have this structure already created before releasing for the first time, otherwise it will fail!

Maven Pom configuration

SVN metadata

Add scm metadata for locating the artifact in the svn

<scm> <connection>scm:svn:${svn.url.base}/trunk/${artifactId}</connection> <developerConnection>scm:svn:${svn.url.base}/trunk/${artifactId}</developerConnection> <url>{svn.url.base}/trunk/${artifactId}</url> </scm>

//NOTE that we are using properties for not hardcoding the svn url. This way, later we can move up this scm metadata to a single place in a parent pom letting children define just what's particular for them, like path in svn

Define POM Properties

Add the following properties to your pom

<properties> <svn.folder>scm/uqbar-parent-project/</svn.folder> ////TODO: CHANGE THIS!! </properties>
  • svn.folder: is the path to the project within svn repository. Starting (and NOT including) the root (repoAr).

Define SCM location

As we are using maven properties to avoid repeating configuration values (DRY principle -don't repeat yourself-), the scm maven configuration will be autogenerated based on that properties.
We cannot inherit this information from the parent pom, since the scm location is unique for every artifact.
So, you'll need to add the following generic scm configuration to your pom.

<scm> <connection>scm:svn:${svn.url.base}/${svn.folder}</connection> <developerConnection>scm:svn:${svn.url.base}/${svn.folder}</developerConnection> <url>${svn.url.base}/${svn.folder}</url> </scm>

Configurar Entorno de Trabajo


  • Subversion client: Maven uses the "svn" command for commiting changes made to the pom, and also for tagging the project. So you'll need a subversion command line client installed in your machine dispite the fact that you could already have another client like subclipse or tortoise.
    • download the latest (at least 1.6.x) release from Subversion client: svn-win32-X.X.X.zip
    • extract .zip (in a folder where it will remain installed)
    • add the intallation path in the Path environment variable, to add svn available in the command line: ("intallation folder" \ bin)
    • open a command prompt and run "svn --version" to verify that it is correctly installed.


Eclipse maven configuration

  • To this is necessary download in your eclipse workspace the SCM SDG project:please download it from:https://walle/subversion/repoAr/scm/uxp.maven.scm/trunk. It will be used to define default and usefull mvn commands including release commands. Also define the variables svnUser and svnPassword correctly on arguments variables



Configure you project's pom.xml

This is necessary in order to reuse some general configuration and configure the svn connection parameters for maven. In order to do this, look for "New project's standard pom setup" in the uxp.maven.scm's project pom.xml and copy (and configure) the commented code into your project's pom.

Add artifactory repository to maven (FOR DOWNLOADING)

You need to tell maven about our internal maven repository (artifactory) so it will be able to resolve and download our internally deployed artifacts (our projects, like contactdirectory-api, servicemanage-pages, etc). To do this, add the following profile to the section of your $M2_HOME/conf/settings.xml. It contains repository's declarations.

<settings> <!-- Authentication information for local user --> <servers> <!-- Release server --> <server> <id>mis-releases</id> <username>TU_USUARIO_ARTIFACTORY</username> <password>TU_PASSWORD</password> </server> <!-- Snapshot server --> <server> <id>mis-snapshots</id> <username>TU_USUARIO_ARTIFACTORY</username> <password>TU_PASSWORD</password> </server> <!-- Site Generated server --> <server> <id>tomcat4projectsites</id> <username>tomcat</username> <password>PASSWORD</password> </server> </servers> <!-- Redefine central mirror in order to redirect default internet access to local server --> <mirrors> <mirror> <id>central-mirror</id> <name>Internal mirror for central</name> <url>http://miserver:8081/artifactory/repo</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>snapshots-mirror</id> <name>Internal mirror for snapshots</name> <url>http://miserver:8081/artifactory/repo</url> <mirrorOf>snapshots</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>uxp</id> <activation> <activeByDefault>true</activeByDefault> </activation> <!-- Fill with the local path from the user's PC --> <properties> <jdk_java>PATH_JAVA_1_4_EXECUTABLE</jdk_java> <jdk5_java>PATH_JAVA_5_0_EXECUTABLE</jdk5_java> <jdk6_java>PATH_JAVA_6_0_EXECUTABLE</jdk6_java> <jdk_javac>PATH_JAVA_1_4_COMPILER</jdk_javac> <jdk5_javac>PATH_JAVA_5_0_COMPILER</jdk5_javac> <jdk6_javac>PATH_JAVA_6_0_COMPILER</jdk6_javac> <compilerVersion>1.4</compilerVersion> </properties> <repositories> <!-- Default repositories for Release and snapshots --> <repository> <id>mis-releases</id> <url>http://miserver:8081/artifactory/repo</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <!-- Default repositories for Maven plugins --> <pluginRepository> <id>central</id> <url>http://miserver:8081/artifactory/repo</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> </pluginRepositories> </profile> </profiles> </settings>

Set artifactory's local repository user and passwd (FOR UPLOADING)

In order to release (or deploy) artifacts into the sdg maven artifactory repository you need a user and password with permissions to do that.
Then, you need to tell your maven to use that user and passwd adding the following entries to you $M2_HOME/conf/settings.xml

... <servers> <server> <id>mis-releases</id> <username>YOUR_ARTIFACTORY_USER</username> <password>YOUR_ARTIFACTORY_PASSWORD</password> </server> <server> <id>mis-snapshots</id> <username>YOUR_ARTIFACTORY_USER</username> <password>YOUR_ARTIFACTORY_PASSWORD</password> </server> <server> <id>tomcat4projectsites</id> <username>tomcat</username> <password>tomcatcarola</password> </server> </servers> ...


Otherwise you'll get the following error

[INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] Error deploying artifact: Failed to transfer file: http://miserver:8081/artifactory/mis-releases@repo/com/gemalto/webcare/parent/1.1/parent-1.1.pom. Return code is: 401 Unauthorized

Set Eclipse M2_REPO variable

Set a M2_REPO variable into your eclipse to point to your local repository.

NOTE: this is unnecessary if you have installed the m2eclipse plugin

Generando Paquetes Customs con Assembly

Configurar POM

Hay que agregar el plugin de assembly en el pom del proyecto.

<build> <plugins> ... <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>src/main/assembly/ota-assembly.xml</descriptor> <descriptor>src/main/assembly/cci-assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>make-assembly</id> <!-- this is used for inheritance merges --> <phase>package</phase> <!-- append to the packaging phase. --> <goals> <goal>attached</goal> </goals> </execution> </executions> </plugin> ... </plugins> </build>

A este se le indica el path a un xml de configuracion del assembly, relativo al proyecto.

Configuracion del Assembly Plugin

El formato completo del archivo de configuracion esta aca Se pueden indicar los siguientes parametros:

  • format: formato del empaquedato final. Puede ser
    • zip
    • tar.gz
    • tar.bz2
    • jar
    • dir
    • war
    • and any other format that the ArchiveManager has been configured for
  • dependencySets: Especifica como empaquetar las dependencias de este proyecto. Ej:
<dependencySets> <dependencySet> <outputDirectory>/lib</outputDirectory> <unpack>false</unpack> <scope>runtime</scope> </dependencySet> </dependencySets>
Esto generara' un directorio "lib" que contendra' todas las dependencias con scope runtime+compile
  • fileSets: especifica directorios y archivos a copiar y a que' folder destino.
<fileSets> ... <fileSet> <directory>src/main/resources</directory> <outputDirectory>/config</outputDirectory> <includes> <include>billingConfig.xml</include> </includes> </fileSet> ... </fileSets>
Esto copiara' el contentido del directorio src/main/resources al directorio de salida "config"

Corriendo el Assembly

  • run "mvn assembly:assembly" on your project.
  • O, si esta' configurado como dice arriba, incluido en el ciclo de vida del packaging se puede correr "mvn package"
Esto generara' el empaquetado en la carpeta "target" del proyecto.

Usando diferentes versiones de Java

Java 1.5 projects

The following pom.xml shows the configuration you need to add in order to work with java 1.5.
Also check that you have your settings.xml well configured according to our standards.


The important lines are:

  • executable = jdk6_javac
  • compilerVersion = compilerVersion
  • <source>1.5</source>
  • <target>1.5</target>
  • And <jvm> for surefire plugin (to execute tests).

Using for compilation a version higher than the one expected has still some risks, for example:
- In my code I do someString.isEmpty(); using jdk1.6 in my eclipse
- I compile with maven using jdk 1.6,indicating 1.5 compliance => Compilation is done without errors.
- I run the app with a 1.5 jre => NoSuchMethodError! (because isEmpty() was introduced in java 1.6)

Integración Continua con Hudson y Vínculo con Maven

Continuous Integration


Keep code & snapshots in-sync

  • Description: Deploy new snapshots once a change has been made to the code.
  • Process: An svn commit will trigger a new build in Hudson that will run all the test. If all goes right then it will deploy a new snapshot to the artifactory repository. Keeping it updated with changes in code (svn)

Autodeploy webapps for instant access

  • Description: Auto deploy wars to a local enterprise webserver for instant access, usually for testing purpous.
  • Process: Like the previous function, after a build has succeded it will deploy the artifact to a tomcat webserver. It uses the hudson deploy plugin.



HudsonEclipsePlugin.JPG hudsonTray.jpg

Unzip it and change the hudson.properties file content with our hudson URL