Configure Maven scm plugin to use serverID from settings.xml

2.6k Views Asked by At

I have a settings.xml file with some servers set:

<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">

 ...
  <servers>

    <server>
      <id>server1</id>
      <username>user1</username>
      <!-- encrypted like https://maven.apache.org/guides/mini/guide-encryption.html  -->
      <password>{xxxxx}</password>
    </server>

    <server>
      <id>server2</id>
      <username>user2</username>
      <!-- encrypted like https://maven.apache.org/guides/mini/guide-encryption.html  -->
      <password>{xxxxx}</password>
    </server>

    <server>
      <id>svn</id>
      <username>userSVN</username>
      <!-- encrypted like https://maven.apache.org/guides/mini/guide-encryption.html  -->
      <password>{xxxxx}</password>
    </server>

  </servers>
...

I read here that it is not possible to set a specific server to the scm plugin, and that you have to add a property to your pom.xml

  <project>
   ...
    <properties>
      <project.scm.id>my-scm-server<project.scm.id>
    </properties>
  </project>

Here is my pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.0.M7</version>
  </parent>

  <groupId>org.test</groupId>
  <artifactId>test</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <svnRoot>xxx</svnRoot>
    <projectSvnPath>xxx</projectSvnPath>
    <svnRootUrl>https://xxx</svnRootUrl>
    <scmRoot>scm:svn:${svnRootUrl}</scmRoot>
    <project.scm.id>svn</project.scm.id>
  </properties>

  <scm>
    <connection>${scmRoot}${svnRoot}/trunk/${projectSvnPath}</connection>
    <developerConnection>${scmRoot}${svnRoot}/trunk/${projectSvnPath}</developerConnection>
  </scm>

  <build>
      <plugins>
        <plugin>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.5.1</version>
          <dependencies>
            <dependency>
              <groupId>com.google.code.maven-scm-provider-svnjava</groupId>
              <artifactId>maven-scm-provider-svnjava</artifactId>
              <version>1.10.1</version>
            </dependency>
            <dependency>
              <groupId>org.tmatesoft.svnkit</groupId>
              <artifactId>svnkit</artifactId>
              <version>1.8.7</version>
            </dependency>
          </dependencies>
          <configuration>
            <tagBase>${svnRootUrl}${svnRoot}/tags/${projectSvnPath}</tagBase>
            <branchBase>${svnRootUrl}${svnRoot}/branches/${projectSvnPath}</branchBase>
            <scmCommentPrefix>[maven-release-plugin]</scmCommentPrefix>
            <svn>javasvn</svn>
          </configuration>
        </plugin>
        <plugin>
          <artifactId>maven-scm-plugin</artifactId>
          <version>1.9</version>
          <dependencies>
            <dependency>
              <groupId>com.google.code.maven-scm-provider-svnjava</groupId>
              <artifactId>maven-scm-provider-svnjava</artifactId>
              <version>1.10.1</version>
            </dependency>
            <dependency>
              <groupId>org.tmatesoft.svnkit</groupId>
              <artifactId>svnkit</artifactId>
              <version>1.8.7</version>
            </dependency>
          </dependencies>
          <configuration>
            <connectionType>connection</connectionType>
            <providerImplementations>
              <svn>javasvn</svn>
            </providerImplementations>
            <message>Maven commit</message>
          </configuration>
        </plugin>
      </plugins>
    </build>


  <profiles>
    <profile>
      <id>commit-pom</id>
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-scm-plugin</artifactId>
            <executions>
              <execution>
                <phase>validate</phase>
                <goals>
                  <goal>checkin</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <includes>pom.xml</includes>
              <message>commit with profile commit-pom</message>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </profile>

  </profiles>
</project>

I try to run a mvn versions:update-parent and my build fail with

svn: E170001: Authentication required for 'https://xxx:443 Subversion Repository 'xxx' '

Here is the Maven command:

/bin/apache-maven-3.2.5/bin/mvn clean versions:update-parent -DallowSnapshots=true validate -Pcommit-pom -B -U --settings ../settings-maven/null_settings.xml --global-settings ../settings-maven/full-settings.xml

I tried with a non-encrypted password and it doesn't work too...

Thanks for your help!

1

There are 1 best solutions below

0
On

The answer was on this page

In the settings.xml via a server entry, using the host name from the connection URL as the server id

If my SVN server URL is "https://myserver.com" the id of the server in the settings.xml has to be "myserver.com"