Apache Maven tips and tricks: war plugin vs assembly plugin

When in #apache #maven you have multiple dependencies with the same artifact id but different group id 

<dependencies>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId1</groupId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId2</groupId>
        <version>1.2</version>
    </dependency>
    <dependency>
        <artifactId>any</artifactId>
        <groupId>groupId3</groupId>
        <version>1.3</version>
    </dependency>
</dependencies>

So it’ll look like this in WEB-INF/lib

-rw------- 1 user grp  135851 Aug 24 12:21 grp1-any-1.1.jar  
-rw------- 1 user grp 1406696 Sep 18 11:51 grp2-any-1.2.jar  
-rw------- 1 user grp   88873 Aug 19 13:58 grp3-any-1.3.jar 

Apache #maven war plugin is able to detect this case and will automatically add the groupId to resolve filename conflicts. If it would not do that the last one name any.jar would win

 In #Maven Assembly this will not occur, and the last file name will be the only one available. There is at least two way to solve this issue:

  1. Use unique groupid and artifactid name: something you can do across your module code, it can be done if these dependencies are real 3rd party librairies
  2. Use the outputFileNameMapping in assembly 
<outputFileNameMapping>${artifact.groupId}-${artifact.artifactId}-${artifact.baseVersion}${dashClassifier?}.${artifact.extension}</outputFileNameMapping> 
${artifact.artifactId}-${artifact.baseVersion}.${artifact.extension}

Another use case for outputFileNameMapping is when you want to remove the timestamp from filename but keep the version in assembly dependencySet

Dockerized Maven

An example driven presentation on how we leverage custom Docker containers (maven, npm, oc client) to handle build dependencies on local workstations, provide clean Jenkins slaves, run tests inside orchestrated deployments or run tests inside OpenShift projects. By Matthias Bertschy from sicpa.

Slides

Recorded by me at Docker Meetup group 5 Oct. 2016

Review: Getting Started with Apache Maven by Russell Gold

Some time ago I was asked if I would like to write a review about one of the new video courses from Packt Publishing. It was “Getting Started with Apache #Maven” http://bit.ly/1fycmpP by Russell Gold and since I have been using Maven for some years now (since 2007) and did publish some articles myself, I thought it would be nice to help them promote Apache #Maven.

The course is organized in eight chapters, forty videos with a length between two and five minutes, for a total length of two hours. The aim of the course is to provide the shortest path to use effectively Maven

You can download the course as a single zip file. After unpacking the file to a local hard disk you find a user guide, support information, a reference to the code examples and the video files. As you may notice I said “reference to the code examples”. Even if the name of the file “Code Bundle.zip” it contains only a file with the link to the source code on github.

Continue reading Review: Getting Started with Apache Maven by Russell Gold

Apache Maven copy local file to a remote server server using SSH

I will show you in an Apache #Maven configuration file how to copy files to server each time the package phase is executed.

Solution with Ant SCP task

This snippet of code is a ready to use code that make use of Apache Ant task scp, Just put this snippet of code in your #Maven module where the assembly is executed or anywhere else to push all tar.gz files to a server just run a #maven mvn package, you can add as many ant task and push to many server the same file during the reactor build.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <executions>
        <execution>
            <id>server-copy</id>
            <goals>
                <goal>run</goal>
            </goals>
            <phase>package</phase>
            <configuration>
                <target>
                    <echo message="Push to server/home/"/>
                    <scp trust="yes" todir="user:password@server:/home/">
                        <fileset dir="${basedir}/target">
                            <include name="**/*.tar.gz"/>
                        </fileset>
                    </scp>
                </target>
            </configuration>
        </execution>
    </executions>
    <dependencies>
        <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-jsch</artifactId>
            <version>1.8.2</version>
        </dependency>
    </dependencies>
</plugin>

Solution with #maven-deploy-plugin

The #maven-deploy-plugin allows you to configure the deploy phase to deploy to a server using scp. There is a page in the documentation that describes how it can be done.

Deploy #maven artifact using Maven Wagon SCP

Another alternative would be to use Maven Wagon SCP like described in this post for example

List conflicting dependencies in the Maven reactor

The Maven Dependency Plugin among other things include a dependency:analyze-duplicate

The dependency plugin provides the capability to manipulate artifacts. It can copy and/or unpack artifacts from local or remote repositories to a specified location.

This Apache #Maven plugin is really feature rich and provide a lot of interesting goals:

Continue reading List conflicting dependencies in the Maven reactor

Break Maven build when there is a dependency conflict

Scenarios

  • You want to control #Maven during dependency resolution and break the build if some conditions are not met,
  • You want to detect dependencies conflict early during the build,
  • You want to avoid anybody in your team to use the dependency x in the version y

This is where the Maven Enforcer Plugin will assist you:

The Enforcer plugin provides goals to control certain environmental constraints such as #Maven version, JDK version and OS family along with many more standard rules and user created rules.

Add in your pom.xml the following to configure the plugin

Continue reading Break Maven build when there is a dependency conflict

OSGi-Bundle with the Maven-Bundle-Plugin

OSGi (Open Service Gateway Initiative) is a #Java framework for developing and deploying modular software programs and libraries.OSGi has two parts. The first part is a specification for modular components called bundles, which are commonly referred to as plug-ins. The specification defines an infrastructure for a bundle’s life cycle and determines how bundles will interact.  The second part of OSGi is a #Java Virtual Machine (JVM)-level service registry that bundles can use to publish, discover and bind to services in a service-oriented architecture (SOA).

In this small post, I will show you how to make your first OSGi bundle using the Bundle Plugin for #Maven from Apache Felix

Continue reading OSGi-Bundle with the Maven-Bundle-Plugin

Keep your software stack up to date with the Apache Maven Versions Plugin

It is not unusual in a project to have a huge number of third party artifacts and Plug-in. Apache #Maven help you keep track of them, along with their transitive dependencies.

But how do you know when a new version of an artifact is available?  This is where the #Maven Versions plug-in come hand in.

The Versions Plug-in is used when you want to manage the versions of artifacts in a project’s POM.

By running

mvn versions:display-dependency-updates

in any Apache #Maven project or modules, you’ll get for example (we have a lot of 25 #Maven modules, here is only one presented as an example, the list being too long)

[INFO] -------------------------------------------------------------------------------------------------- 
[INFO] Building Unnamed - com.innoveo:skye-services-api:jar:2.2.0-M-06 
[INFO] -------------------------------------------------------------------------------------------------- 
[INFO] 
[INFO] The following dependencies in Dependency Management have newer versions: 
[INFO]   junit:junit ............................................. 4.4 -> 4.8.1 
[INFO]   log4j:log4j ......................................... 1.2.15 -> 1.2.16 
[INFO]   org.springframework:spring ...................... 2.5.6 -> 2.5.6.SEC02 
[INFO]   org.springframework:spring-test ............... 2.5.6 -> 3.0.4.RELEASE
Continue reading Keep your software stack up to date with the Apache Maven Versions Plugin

Auto deployment of Maven artifacts to Oracle Weblogic

I found  this time a  new way to deploy #Maven artefacts using the Oracle Weblogic Ant API!

If you remember my previous post, there is many ways to deploy your war/ear to Oracle Weblogic

  1. Using Oracle Weblogic development mode, a mode in which a simple copy of your files in a specific autodeploy directory trigger the update/install of these
  2. Using Maven Cargo, this work only if your Oracle Weblogic container is local (see here) on the same machine, where Apache #Maven is running
  3. Using a very old #Maven plugin (2008), local and remote container are supported, but our builds were sometimes hanging during pre integration phase for no apparent reasons.

And now using the official ANT API of Oracle, by far the MOST stable of all!

Continue reading Auto deployment of Maven artifacts to Oracle Weblogic

Apache Maven BEA Weblogic 10.3 remote deployment

In this small post I will show you how to deploy automatically some artifacts of your build into Weblogic 10.3 by using the weblogic-maven-plugin

This plugin will support various tasks within the Weblogic 8.1 and 9.x environment. Such tasks as deploy, undeploy,clientgen,servicegen, and appc are supported as well as many others. The plugin uses exposed API’s that are subject to change but have been tested in 8.1 SP 4-6 and 9.0 – 9.2 MP3. There are two versions of the plugin to support the two environments based on differences in the JDK. The 9.x version is currently being refactored to support the standard JSR supported deployment interface

Continue reading Apache Maven BEA Weblogic 10.3 remote deployment