简体   繁体   English

配置Maven scm插件以使用settings.xml中的serverID

[英]Configure Maven scm plugin to use serverID from settings.xml

I have a settings.xml file with some servers set: 我有一个设置了一些服务器的settings.xml文件:

<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 在这里阅读不可能为scm插件设置特定的服务器,并且必须在pom.xml中添加一个属性。

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

Here is my pom.xml 这是我的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 我尝试运行mvn版本:update-parent,并且我的构建失败

svn: E170001: Authentication required for ' https://xxx:443 Subversion Repository 'xxx' ' svn:E170001:' https:// xxx:443 Subversion Repository'xxx''需要认证

Here is the Maven command: 这是Maven命令:

/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! 谢谢你的帮助!

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 通过服务器条目在settings.xml中, 使用连接URL中的主机名作为服务器ID

If my SVN server URL is " https://myserver.com " the id of the server in the settings.xml has to be "myserver.com" 如果我的SVN服务器URL是“ https://myserver.com ”,则settings.xml中服务器的ID必须是“ myserver.com”

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

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