开发者

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 app开发者_JS百科reciated.

Thanks in advance, Raphael


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜