Different SCM for different profiles in Maven

半世苍凉 提交于 2021-02-18 15:18:11

问题


In my project we have to use maben-build-number plugin to construct the final name of the jar, for that purpose we use the revision of the SCN, so we need SCM

But we have two SVN on controlled environment without direct access and on our local test environment, so for our pouproses we have to use:

<scm>
    <connection>scm:svn:http://dev.com/svn_repo/trunk</connection>
    <developerConnection>scm:svn:https://dev.com/svn_repo/trunk</developerConnection>
    <url>http://dev.com/view.cvs</url>
</scm>

But for client env:

      <scm>
        <connection>scm:svn:http://client.com/svn_repo/trunk</connection>
        <developerConnection>scm:svn:https://client.com/svn_repo/trunk</developerConnection>
        <url>http://client.com/view.cvs</url>
      </scm>

Is it possible to configure this in the different profiles. I tried

<profiles>
  <profile>
    <id>local</id>
    <scm>
        <connection>scm:svn:http://client.com/svn_repo/trunk</connection>
        <developerConnection>scm:svn:https://client.com/svn_repo/trunk</developerConnection>
        <url>http://client.com/view.cvs</url>
      </scm>
  </profile>
  <profile>
    <id>remote</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <scm>
        <connection>scm:svn:http://client.com/svn_repo/trunk</connection>
        <developerConnection>scm:svn:https://client.com/svn_repo/trunk</developerConnection>
        <url>http://client.com/view.cvs</url>
      </scm>
  </profile>
</profiles>

But when I use the profile -Plocal, nothing happens?


回答1:


I solved this problem by creating a property for the SCM connection details I need to change for different profiles. Here is a summary of what I did.

Defined the property and it's default value the properties block.

<properties>
    <developerConnectionUrl><!-- developerConnection url here --></developerConnectionUrl>
</properties>

Set the scm block properties to use the global properties.

<scm>
    <developerConnection>${developerConnectionUrl}</developerConnection>
</scm>

Created a profile which changes the global property as required.

<profiles>
    <profile>
        <id>local</id>
        <properties>
            <developerConnectionUrl><!-- developerConnectionUrl url for profile --></developerConnectionUrl>
        </properties>
    </profile>
</profiles>

As far as I know and from a quick scan of the schema the scm tag can only be used at the top level in the POM and is not valid inside the profile tag



来源:https://stackoverflow.com/questions/37893346/different-scm-for-different-profiles-in-maven

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!