views:

32

answers:

1

I have a maven project infrastructure like this:

/trunk/all/pom.xml
/trunk/all/libs/lib1/pom.xml
               /lib2/pom.xml
               ...
/trunk/all/projects/p1/pom.xml
                   /p2/pom.xml
                   ...

You see, I have a lot of libraries and a lot of projects using these libraries.

All this is combined to one multi module project, because I like to

  • import the top project into eclipse and have all my libraries and projects available at once
  • only do a single mvn test to compile and test all my code after I've done some global refactorings.

Currently, all my modules are version 1.0-SNAPSHOT.

Now I want to release project p2 and all libs p2 uses (e.g. lib1 and lib2) to version 1.0. After that I do some code modifications on lib1, but none on lib2.

I want the next release of p2 being version 1.1, using lib1 in version 1.1 (it was modified since the last release), but lib2 still in version 1.0 (since it wasn't modified).

More general: If I do a release, I want to increase the minor numbers of the project being released and of all changed libraries since the last release.

Question

Do I have to take care for all the module versions by myself or is there a plugin that is able to do the required work for me?

+1  A: 

Do I have to take care for all the module versions by myself or is there a plugin that is able to do the required work for me?

Well, if you don't want to keep the versions of the various artifacts (projects, libs) in sync with the version defined in all/pom.xml (i.e. just inherit it through the whole hierarchy), I'm afraid you'll have to start to manage them manually. I'm just not sure to understand why you wouldn't bump the version of say lib2 even if you didn't make any change to it. With your current svn repository structure, all artifacts have the same release lifecycle somehow (when you'll tag the trunk, you'll tag everything in it).

Now, if p1 and p2 (I'll ignore the libs for the sake of simplicity) have an independent release cycle, I would recommend a multiple "trunk/tags/branches" structure as described in this thread:

myrepo
  + .links (2)
    + trunks
      + pom.xml
  + parent-pom (1)
    + trunk
      + pom.xml
  + project-A
    + trunk
      + pom.xml
  + project-B
    + trunk
      + pom.xml 

1) The parent POM of the project has an own release cycle. Every component's POM will use it as parent (referenced simply with groupId and artifactId, no relativePath). For a release you'll have to release the parent POM first.

2) This is a construction to enable easy check outs of a specific branch of the project i.e. normally the trunk. A subversion user checks out myrepo/.links/trunk to get the head revision of all sources. The trick is, that that directory contains external links (i.e. with the svn:externals property) to the trunks of all other modules of this project (parent-pom, project-A, project-B). The pom.xml in this directory is never released, it contains simply a modules section for the three modules to enable a multi module build. With this construct you're able to setup easily branches e.g.:

myrepo
  + .links
    + branch-2.x
      + pom.xml

I've used this setup many times (I already wrote about it here on SO, see the related questions below), it works very well. Actually, many projects, including Maven, are using this approach, it's not a fantasy one.

This will not solve your "automagic" version handling (I don't know any solution for that) but at least, this structure plays nicely with the Maven Release Plugin and would support your independent release cycle requirements.

See also

Related questions

Pascal Thivent
In my last project, I built a command line tool that let you automatically increment or decrement major, minor or increment version of a specific module while automatically updating all dependencies to it in other modules (it understood dependencies, parents and even artifactItems). It was great fun to use, but eventually we realized that we don't need individual module versions and so we ditched it. Great answer btw (+1)
seanizer
@seanizer Interesting, although I didn't really need this granularity so far. Written in Groovy? :)
Pascal Thivent
No, plain java. used no maven code, either. I'll see if I can find it and post it somewhere.
seanizer
@pascal: Thanks for your answer, I'll rethink my current directory structure. But I think your suggestion is more work to maintain. With my structure I tag the whole structure when releasing a single project. That's all I have to do. The version numbers of the modules shall only give my customers an idea which part of the code (which modules) have changed.
tangens
@tangens: You're welcome. I'm not sure to understand if you are using the maven-release-plugin or not, my answer was maven-release-plugin oriented (as suggested by the tag). I'm also not sure to understand why changing the version numbers of modules is a concern for customers (you might have good reasons but why not using release notes?) but moving to manual version management conflicts with your maintenance concerns, IMO.
Pascal Thivent
@pascal: I've tried the release plugin, but I've found no way to use it like I wanted/ needed it. Right now, the version numbers are a 'nice to have', but I could life without them if I'd have to manage them manually.
tangens
@pascal: My customers asked for version numbers, because they could focus their tests on modules that changed.
tangens
@tangens: I hope they are ready to pay for the generated overhead :)
Pascal Thivent