Resolving Dependency Conflicts in Maven

Posted by Martin Homik | Posted in Java | Posted on 12-02-2008

0

Today, I ran into a problem which turned out to be a Maven dependency conflict. It all began with running a a set of JUnit tests on my AppFuse project with MySQL as backend. Even standard add/remove tests on the simplest class terminated with an InvalidDataAccessResourceUsageException caused by Hibernate. When I switched to PostgreSQL, all tests were successful.

At first, I thought that the error originated in MySQL or in my POM parameters, but I could not find anything on the net that confirmed my suspicion. Eventually, I came across a Hibernate Jira issue, which explains that particular behaviour. Hibernate did not specify any value for row id.

I searched AppFuse’s POM for a Hibernate dependency and found this: the POM itself does not state that it requires a specific Hibernate version. But it relies on AppFuse’s static repository and its dependencies which are implicitly present in my POM. However, I’ve been working with hyperjaxb3 recently which depends on an hibernate-entitymanager of version 3.3.1.ga which in turn includes a buggy Hibernate jar mentioned in the issue. As hyperjaxb3’s dependency versions are lower than those of AppFuse, Maven decided to use the lower version to get things running. Hence, the problem.

Now, to solve the problem you can either remove hyperjaxb3’s dependency or just change tge version to a version range.

  1. <dependency>
  2.    <groupid>org.hibernate</groupid>
  3.    <artifactid>hibernate-entitymanager</artifactid>
  4.    <version>[3.3.1.ga,]</version>
  5.    <scope>test</scope>
  6. </dependency>

The range means that Maven should use the latest available hibernate-entitymanager, but no older than that of version 3.3.1.ga.

Maven Archetypes

Posted by Martin Homik | Posted in Java | Posted on 11-02-2008

0

Assume you are a beginner and someone tells you to implement a JAR, J2EE, portlet or some other project. How should you start? How should you organize your project? To base your project on best-practice use Maven’s archetype plug in. Just select the project type you would like to have and let the Maven create the structure for you. Version 1.0-alpha-7 supports the following archetypes:

  • maven-archetype-archetype
  • maven-archetype-j2ee-simple
  • maven-archetype-mojo
  • maven-archetype-portlet
  • maven-archetype-profiles (currently under development)
  • maven-archetype-quickstart
  • maven-archetype-simple (currently under development)
  • maven-archetype-site
  • maven-archetype-site-simple
  • maven-archetype-webapp

Take some time and create different projects and explore its differences. It will provide you with a broader overview and you get the feeling for how to set up projects and what kind of files are needed for a project. A few more archetypes can be found here.

The latest snapshot of Version 2.0 provides even more archetypes and a much more convenient way to create projects. Try it!