• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Converting existing maven project with circular dependanices

Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All
I have an existing ant project which builds 20 jars
All these jars come from different packages and 2 jars have same packages in both the jars

I am making a new maven project each jar with a parent pom too

As I started converting to maven and adding dependencies, I discovered that some of the jars have circular dependencies (Classes in Package P1( in JAR1) depends on classes in package P2 (in JAR2) and Classes in package P3(in JAR2) depends on classes in package P4(in JAR1) )

The jars independently builds fine since ant first compiles them and then referes to source code and just packages .class files inside jars.

Is there an easier way to move the code across the jars to remove circular dependency so that each jar builds fine?

I made use of JBoss Tattletale to find any dependencies and adding dependencies in child pom but its getting really tricky with so many inter dependencies of classes over different jars

Posts: 5856
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds to me like whoever created the original build took a single logical project and created separate JAR files only for organizational purposes. My first recommendation would be to forget about the 20 JAR files and instead have only one project and create only one JAR file. Beyond that, if you can determine separate groups of cunctionality, you might be able to split this one project into 2 or more projets. For example, if there are utility classes in a util package and those don';t depend on anything else, there is one separate JAR. Then perhapds there are some packages that define an API or interface, and they depend on on the classes in the util packkage, those could go into another.

However, it you still want 20 JARs, there is a way to do it. One of the projects I migrated from Ant created a JAR of all classes in all packages, and then create a second JAR that contains only a few of the classes (less than 10). I couldn't break those classes into a separate projet because there were cross dependencies with the rest of the classes in the larger project. So I used the Maven JAR plugin to create a second JAR file containing only the desired classes, which I attached to the project using a classifier. In other words, I ended up with the following artifacts in the repository:
- xxx.pom
- xxx.jar
- xxx-foo.jar

Here is how I set up the plugin:

Then for any other projects that needed this particular JAR, I included the classifier in the dependency.
Posts: 2759
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THat's one of the problems with ant. It's so flexible, that it is easy to do things the wrong way. The whole point of having seperate JAR files is so you can reuse them between projects. You should be able to take a bunch of jar files, and reuse it in another project. If you have JAR1 dependent on JAR2, then JAR2 can be reused without JAR1, and JAR1 has to be reused with JAR2. However, if JAR1 and JAR2 have a circular dependeny, you might as Well put them together in a single JAR. There's no point in splitting the JARs

It's obvious that you need to restructure the 20 JAR files as part of mavenizing the build. Your jar files are all messed up right now. First thing that I would do is step away from Maven and first figure out what JAR files you really need.

Most people structure the maven modules based on the modules of your applications. WHen you do you design, you identify modules, and you create a maven sub-modul for every module. This makes it easy to understand the maven project structure.
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic