简体   繁体   English

相对于POM中的父SCM URL的SCM URL

[英]SCM URL relative to parent SCM URL in POMs

I have a Maven project made of several modules and sub-modules. 我有一个由几个模块和子模块组成的Maven项目。 I use SVN to version the source files. 我使用SVN来版本化源文件。

The short story 短篇小说

How do I specify URL in scm properties of a POM file, that are relative to the ones of its parent. 如何在POM文件的scm属性中指定URL,这些属性与其父级的URL相关。

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. 为此,我在我的存储库中有两个SVN布局。 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. 一个包含所有主干/分支/标签混乱,另一个包含一个干净的准备结帐工作目录,其中包含svn:对中继的外部引用。

This looks like this; 这看起来像这样; You have the real world SVN layout, with trunk/branches/tags mess: 你有真实世界的SVN布局,主干/分支/标签混乱:

  • pom.xml (main parent) pom.xml (主要父母)
  • utils utils的
    • branches 分支机构
    • tags 标签
    • trunk 树干
      • pom.xml , src, target, etc... pom.xml ,src,target等...
  • data-model ( released ) 数据模型 (已发布
    • branches 分支机构
    • tags 标签
    • trunk 树干
      • pom.xml 的pom.xml
      • lib LIB
        • pom.xml , src, target, etc... pom.xml ,src,target等...
      • server 服务器
        • pom.xml , src, target, etc... pom.xml ,src,target等...
      • client 客户
        • pom.xml , src, target, etc... pom.xml ,src,target等...
  • bin-modules 斌模块
    • bin-module-1 ( released ) bin-module-1 (已发布
      • branches 分支机构
      • tags 标签
      • trunk 树干
        • pom.xml , src, target, etc ... pom.xml ,src,target等...
    • bin-module-2 ( released ) bin-module-2 (已发布
      • branches 分支机构
      • tags 标签
      • trunk 树干
        • pom.xml , src, target, etc... pom.xml ,src,target等...

And the clean layout of the working direcotry, hidding the branches/trunk stuff with "svn:externals" tags: 工作区的干净布局,用“svn:externals”标签隐藏树枝/树干的东西:

  • pom.xml (main parent) pom.xml (主要父母)
  • utils (-> utils/trunk ) utils ( - > utils / trunk
    • pom.xml , src, target, etc... pom.xml ,src,target等...
  • data-model (-> data-model/trunk ) 数据模型 ( - > 数据模型/主干
    • pom.xml 的pom.xml
      • lib LIB
        • pom.xml , src, target, etc... pom.xml ,src,target等...
      • server 服务器
        • pom.xml , src, target, etc... pom.xml ,src,target等...
      • client 客户
        • pom.xml , src, target, etc... pom.xml ,src,target等...
  • bin-modules 斌模块
    • pom.xml 的pom.xml
    • bin-module-1 (-> bin-module-1/trunk ) bin-module-1 ( - > bin-module-1 / trunk
      • pom.xml , src, target, etc ... pom.xml ,src,target等...
    • bin-module-2 (-> bin-module-2/trunk ) bin-module-2 ( - > bin-module-2 / trunk
      • pom.xml , src, target, etc... pom.xml ,src,target等...

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. 我在父POM中设置了根SCM URL,Maven正确地暗示了子模块的URL。 I have checked it with mvn help:effective-pom 我用mvn help:effective-pom检查了它mvn help:effective-pom

I have the following scm urls: 我有以下scm网址:

  • root : [root-url] root :[root-url]
  • utils : [root-url]/utils utils :[root-url] / utils
  • data-model : [root-url]/data-model/ 数据模型 :[root-url] / data-model /
  • data-model/lib : [root-url]/data-model/lib data-model / lib :[root-url] / data-model / lib
  • data-model/client : [root-url]/data-model/client 数据模型/客户端 :[root-url] / data-model / client
  • data-model/server : [root-url]/data-model/server 数据模型/服务器 :[root-url] / data-model / server
  • bin-module-1 : [root-url]/bin-module-1/ bin-module-1 :[root-url] / bin-module-1 /
  • bin-module-2 : [root-url]/bin-module-2/ bin-module-2 :[root-url] / bin-module-2 /

But Maven is unaware of the actual SVN layout. 但Maven并不知道实际的SVN布局。 I would like it to see : 我希望看到:

  • root : [root-url] root :[root-url]
  • utils : [root-url]/utils/trunk utils :[root-url] / utils / trunk
  • data-model : [root-url]/data-model/trunk 数据模型 :[root-url] / data-model / trunk
  • data-model/lib : [root-url]/data-model/trunk/lib data-model / lib :[root-url] / data-model / trunk / lib
  • data-model/client : [root-url]/data-model/trunk/client data-model / client :[root-url] / data-model / trunk / client
  • data-model/server : [root-url]/data-model/trunk/server 数据模型/服务器 :[root-url] / data-model / trunk / server
  • bin-module-1 : [root-url]/bin-module-1/trunk bin-module-1 :[root-url] / bin-module-1 / trunk
  • bin-module-2 : [root-url]/bin-module-2/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 . 为此,我需要将一个scm部分添加到data-modelbin-module-1bin-module-2pom.xml中。

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 ? 那么,如何相对于其父SCM URL覆盖SCM路径?

Any help, advice, would be much appreciated. 任何帮助,建议,将不胜感激。

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) 如果没有,仍然有可能以编程方式分配这些值(我将使用GMaven来做到这一点,但你也可以使用antrun插件或编写自定义插件)

First, set a property 首先,设置一个属性

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

Then assign a relative offset to all SCM properties: 然后为所有SCM属性分配相对偏移量:

<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. 您可以将其添加到根pom并进行更改,使其仅在找到属性时运行,然后您可以通过简单地向其添加属性来自动设置n个子模块的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM