Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SCM URL relative to parent SCM URL in POMs

I have a Maven project made of several modules and sub-modules. I use SVN to version the source files.

The short story

How do I specify URL in scm properties of a POM file, that are relative to the ones of its parent.

The long story

Some modules and their sub modules share a common version number / release process, and some use independant ones. For the module with independant version number, I have set up a branches/trunk/tags layout, for the release-plugin to be happy.

For that, I haveb two SVN layouts in my repository. One holds all the trunk/branches/tags mess, the other one holds a clean ready-to-checkout working directory with svn:external references to the trunks.

This looks like this; You have the real world SVN layout, with trunk/branches/tags mess:

  • pom.xml (main parent)
  • utils
    • branches
    • tags
    • trunk
      • pom.xml, src, target, etc...
  • data-model (released)
    • branches
    • tags
    • trunk
      • pom.xml
      • lib
        • pom.xml, src, target, etc...
      • server
        • pom.xml, src, target, etc...
      • client
        • pom.xml, src, target, etc...
  • bin-modules
    • bin-module-1 (released)
      • branches
      • tags
      • trunk
        • pom.xml, src, target, etc ...
    • bin-module-2 (released)
      • branches
      • tags
      • trunk
        • pom.xml, src, target, etc...

And the clean layout of the working direcotry, hidding the branches/trunk stuff with "svn:externals" tags:

  • pom.xml (main parent)
  • utils (-> utils/trunk)
    • pom.xml, src, target, etc...
  • data-model (-> data-model/trunk)
    • pom.xml
      • lib
        • pom.xml, src, target, etc...
      • server
        • pom.xml, src, target, etc...
      • client
        • pom.xml, src, target, etc...
  • bin-modules
    • pom.xml
    • bin-module-1 (-> bin-module-1/trunk)
      • pom.xml, src, target, etc ...
    • bin-module-2 (-> bin-module-2/trunk)
      • pom.xml, src, target, etc...

So far, so good. I have set up the root SCM URLs in my parent POM, and Maven correctly implies the URLs for the sub-modules. I have checked it with mvn help:effective-pom

I have the following scm urls:

  • root : [root-url]
  • utils : [root-url]/utils
  • data-model : [root-url]/data-model/
  • data-model/lib : [root-url]/data-model/lib
  • data-model/client : [root-url]/data-model/client
  • data-model/server : [root-url]/data-model/server
  • bin-module-1 : [root-url]/bin-module-1/
  • bin-module-2 : [root-url]/bin-module-2/

But Maven is unaware of the actual SVN layout. I would like it to see :

  • root : [root-url]
  • utils : [root-url]/utils/trunk
  • data-model : [root-url]/data-model/trunk
  • data-model/lib : [root-url]/data-model/trunk/lib
  • data-model/client : [root-url]/data-model/trunk/client
  • data-model/server : [root-url]/data-model/trunk/server
  • bin-module-1 : [root-url]/bin-module-1/trunk
  • bin-module-2 : [root-url]/bin-module-2/trunk

For that, I need to add a scm section to the pom.xml of data-model, bin-module-1 and bin-module-2.

I have tried something like (for data-model) :

<scm>
    <connection>./data-model/trunk</connection>
    <developerConnection>./sdr/trunk</developerConnection>
    <url>./sdr/trunk</url
</scm>

Or

<scm>
    <connection>${project.parent.scm.connection}/data-model/trunk</connection>
    <developerConnection>${project.parent.scm.developerConnection}/data-model/trunk</developerConnection>
    <url>${project.parent.scm.url}/data-model/trunk</url>
</scm>

But none seem to work. The properties ${...} are not even replaced. So, how do I override a SCM path, relative to its parent SCM URL ?

Any help, advice, would be much appreciated.

Thanks in advance, Raphael

like image 515
Raphael Jolivet Avatar asked Feb 02 '11 14:02

Raphael Jolivet


People also ask

What is the use of scm tag in POM XML?

Assuming that SCM has been configured in the pom. xml and the project directory is managed by a SCM, invoking the checkin goal in the scm will start the commit process for all configured sources in your pom. xml . The files should be added beforehand by an external scm client.

What is SCMs in maven?

Maven SCM supports Maven plugins (for example maven-release-plugin) and other tools by providing them with a common API for source code management operations. You can look at the list of SCMs for more information on using Maven SCM with your favorite SCM tool.

What is scm connection?

SCM Connections provides innovative process design, quality implementations, and sustainable adoption for long-term supply chain forecasting methods.

How does maven release plugin work?

The plugin will extract file revisions associated with the current release. Maven will compile, test and package the versioned project source code into an artifact. The final deliverable will then be released into an appropriate maven repository.


1 Answers

I would have thought that this works:

<scm>
    <connection>${project.parent.scm.connection}/data-model/trunk</connection>
    <developerConnection>${project.parent.scm.developerConnection}/data-model/trunk</developerConnection>
    <url>${project.parent.scm.url}/data-model/trunk</url>
</scm>

If it doesn't, there's still the possibility to assign these values programmatically (I'll use GMaven to do that, but you can also use the antrun plugin or write a custom plugin)

First, set a property

<properties>
    <relativeScmPath>data-model/trunk</relativeScmPath>
</properties>

Then assign a relative offset to all SCM properties:

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>assign-scm</id>
            <phase>validate</phase>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <source>
                <![CDATA[
                def parentScm = project.parent.scm;
                def thisScm = project.scm;
                def relPath = project.properties['relativeScmPath'];
                ['connection','developerConnection','url'].each{
                    thisScm[it] = parentScm[it] + relPath;
                }
                ]]>
                </source>
            </configuration>
        </execution>
    </executions>
</plugin>

You could add this to the root pom and change it so that it runs only if it finds the property, and then you can automatically set the value for n sub modules by simply adding the property to them.

like image 142
Sean Patrick Floyd Avatar answered Sep 28 '22 14:09

Sean Patrick Floyd