Showing posts with label Maven2. Show all posts
Showing posts with label Maven2. Show all posts

Tuesday, January 10, 2012

Checkstyle suppression configuration in Maven

Recently I ran into this checkstyle configuration problem. Basically we have this multi-module maven project and we would like to put checkstyle config and suppression in the parent maven pom but apparently checkstyle maven plugin not very happy with the relative path of suppression config file, for example


<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<suppressionsLocation>config/checkstyle-suppressions.xml</suppressionsLocation>

During the build modules look for checkstyle-suppressions.xml at its own directory not parent and checkstyle plugin just simply ignores the error when file not found. Some people had the same problem with me on Stackoverflow and here too. I just choose the easy solution to add a new property in both parent and children pom files to set the correct location of the config file. 

parent pom

<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
<suppressionsLocation>${main.basedir}/config/checkstyle-suppressions.xml</suppressionsLocation>

<main.basedir>${project.basedir}</main.basedir>

children pom
<main.basedir>${project.basedir}/..</main.basedir>

And there is another way, I guess the better one, to share resource across project in Maven here.

Wednesday, August 24, 2011

Maven surefire plugin and failsafe plugin

In my previous projects, we have been using surefire plugin for both unit test and integration test because we don't really have any housekeeping after integration-test phase in the build.

I just realized today that we should have used failsafe plugin rather than surefire for integration test. To use failsafe plugin add below into your project pom.xml


<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.9</version>
<configuration>
<includes>
<include>Sample.java</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-functional-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<includes>
<include>**/*IntegrationTest.java</include>
<include>**/selenium/**/*Test.java</include>
</includes>
<excludes>
<exclude>none</exclude>
</excludes>
</configuration>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>



If you want to make your build success even with integration test fail just remove the "verify" goal and execution.

Tuesday, August 23, 2011

Maven Web Prototype Project Archetype

Sometimes to create a java web application project prototype is really a daunting task. You need to config web.xml then Spring framework and Hibernate also Unit test, integration test and selenium test so on.

Maven provides the functionality to generate a project from archetype in seconds. An archetype is basically a template or skeleton of a project. More details are available here.

Now I have created an archetype archive attached here with a pom file.

To use the archetype, first you need to install the archive into your local maven repository by command


mvn install:install-file
-Dfile=web-prototype-archetype-1.0-SNAPSHOT.jar
-DpomFile=pom.xml


then generate your own project from the archetype


mvn archetype:generate
-DinteractiveMode=false
-DarchetypeGroupId=melbourne.k.ben
-DarchetypeArtifactId=web-prototype-archetype
-DarchetypeVersion=1.0-SNAPSHOT
-DgroupId=<your group id>
-DartifactId=<your artifact id>


So what inside my target project of this archetype? It is a simple web application based on Spring MVC. The detailed structure :


Web Tier: Tiles+ Spring MVC
DI: Spring and Spring Resource Bundle Message
Test: Mockito + selenium RC
App Server: Glassfish


Notice: the projects only tested in Maven2.0.9 and I haven't added Hibernate into it. Also I am planning to upgrade Spring to 3.0.6 currently using 2.5.6 and selenium RC is quite old as well should upgrade it to web driver.

Wednesday, August 10, 2011

maven2 encoding settings

Recently I set up a development environment on Ubuntu10 and there was a problem with my maven build. Because most existing source code generated from windows and I had an encoding mapping error when building my project in Ubuntu.

To solve it just simply add a property into root pom file.

<properties>
<project.build.sourceEncoding>iso-8859-1</project.build.sourceEncoding>

<project.reporting.outputEncoding>iso-8859-1</project.reporting.outputEncoding>
</properties>

Maven Document