简体   繁体   English

将Perforce scm配置为maven项目以获取最新的更改列表

[英]Configuring Perforce scm into maven project to get latest changelist

I am migrating a project to Maven and as we were used to always reference our builds by the latest change number in our Perforce SCM repository, I would like to be able to extract this information 我正在将项目迁移到Maven,因为我们习惯于通过Perforce SCM存储库中的最新更改编号引用我们的构建,我希望能够提取此信息

I am trying to configure Maven scm plugin via following resources: 我试图通过以下资源配置Maven scm插件:

First I don't understand how to make it work, so if anybody has a fully working example, I will be happy to, on my side I have tried by adding in my pom: 首先,我不明白如何使它工作,所以如果有人有一个完整的例子,我会很高兴,在我这边我尝试添加我的pom:

<scm>
    <connection>
        scm:perforce:localhost:1666://depot/
        <my_project>
            /
            <version>
    </connection>
    <developerConnection>
        scm:perforce:localhost:1666:/depot/
        <my_project>
            /
            <version>
    </developerConnection>
    <url>http://somerepository.com/view.cvs</url>
</scm>
...
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-scm-plugin</artifactId>
        <version>1.6</version>
        <dependencies>
            <!-- P4Maven -->
            <dependency>
                <groupId>com.perforce</groupId>
                <artifactId>p4maven</artifactId>
                <version>[2011,2012)</version>
            </dependency>
        </dependencies>
        <configuration>
            <connectionType>//depot/proto/kernel/kernel/04.00/maven2</connectionType>
            <username>my local username</username>
            <password>xxxxxx</password>
            <includes>**</includes>
        </configuration>
    </plugin>
</plugins>

this is leading me to: 这导致我:

[INFO] --- maven-scm-plugin:1.6:checkout (default-cli) @ kernel ---
mars 27, 2012 9:54:08 AM org.sonatype.guice.bean.reflect.Logs$JULSink warn
Avertissement: Error injecting: org.apache.maven.scm.provider.svn.svnexe.SvnExeScmProvider
java.lang.NoClassDefFoundError: org/apache/maven/scm/command/info/InfoScmResult

Surely forgot something, I will try to read again the instructions and see what I miss, but if anybody knows ... 肯定忘了什么,我会再次阅读说明,看看我想念的,但是如果有人知道的话......

Anyway, my question is rather: is it worth trying it ? 无论如何,我的问题是:是否值得尝试? I don't see in the available actions from scm plugin anything that will help me getting the last change information and integrate it into a reference build number. 我没有在scm插件的可用操作中看到任何可以帮助我获取最后的更改信息并将其集成到引用构建号中的内容。 Shall I develop my own plugin for this ? 我应该为此开发自己的插件吗?

Thanks in advance. 提前致谢。

I got some advice from one of the P4Maven developers that might help. 我得到了一位可能有帮助的P4Maven开发人员的建议。

First, check your configuration. 首先,检查您的配置。 The "..." in the "" tag should be one of the tag names in the "" tag (ie "connection" or "developerConnection") “”标签中的“...”应该是“”标签中的标签名称之一(即“连接”或“developerConnection”)

There two options to use Maven with Perforce SCM. 使用Maven和Perforce SCM有两种选择。

  1. Use the default (built-in) Maven Perforce SCM provider (p4 commandline based) 使用默认(内置)Maven Perforce SCM提供程序(基于p4命令行)

    • Note that you'll need the p4 commandline executable installed 请注意,您需要安装p4命令行可执行文件
    • You can set the username and password using environment variables or JVM args 您可以使用环境变量或JVM args设置用户名和密码

[environment variables] P4CLIENT= P4USER= P4PASSWD= [环境变量] P4CLIENT = P4USER = P4PASSWD =

or 要么

[JVM args] -Dusername= -Dpassword= [JVM args] -Dusername = -Dpassword =

[pom.xml] ... [pom.xml] ......

  ...

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.4</version>
  </plugin>

  ...

... ...

 <!-- SCM Settings -->
  <scm>
    <connection>scmerforce:localhost:1666://depot/someproject</connection>
    <developerConnection>scmerforce:localhost:1666://depot/someproject</developerConnection>
    <url>scmerforce://depot/simple</url>
  </scm>

... ...

  1. Use the P4Maven Perforce SCM provider (P4Java based) 使用P4Maven Perforce SCM提供程序(基于P4Java)

[pom.xml] [pom.xml中]

... ...

  ...

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-scm-plugin</artifactId>
    <version>1.4</version>
    <dependencies>
      <!-- P4Maven -->
      <dependency>
        <groupId>com.perforce</groupId>
        <artifactId>p4maven</artifactId>
        <version>[2011,2012)</version>
      </dependency>
    </dependencies>
    <configuration>
      <connectionType>connection</connectionType>
      <username>someuser</username>
      <password>somepassword</password>
      <includes>**</includes>
    </configuration>
  </plugin>

  ...

... ...

scm4:localhost:1666://depot/someproject scm4:localhost:1666://depot/someproject scm4://depot/someproject scm4:localhost:1666:// depot / someproject scm4:localhost:1666:// depot / someproject scm4:// depot / someproject

... ...

  • Note that for P4Maven we're overriding the default provider inside the "maven-scm-plugin" plugin. 请注意,对于P4Maven,我们将覆盖“maven-scm-plugin”插件中的默认提供程序。

  • Note that we're using "scmp4" (if using P4Maven) instead of "scmperforce" (built-in default) as the provider name, since "perforce" is taken by the existing default implementation. 请注意,我们使用“scmp4”(如果使用P4Maven)而不是“scmperforce”(内置默认值)作为提供者名称,因为现有的默认实现采用“perforce”。

I was struggling with exactly the same problem recently - I just wanted to get a Perforce revision number to use it in maven artifacts (for example as a part of a name). 我最近遇到了完全相同的问题 - 我只想获得一个Perforce版本号,以便在maven工件中使用它(例如作为名称的一部分)。 I checked buildnumber-maven-plugin , but it does not support Perforce at all. 我检查了buildnumber-maven-plugin ,但它根本不支持Perforce。 I also tried maven-release-plugin , but it seems to me as it does too much and I even didn't find out if it will do what I need. 我也尝试了maven-release-plugin ,但在我看来它确实太多了,我甚至没有发现它是否会做我需要的东西。

Anyway I ended up with a solution which I don't like, but it works. 无论如何,我最终得到了一个我不喜欢的解决方案,但它确实有效。 I get this revision number directly with p4 executable via ant and antrun plugin (you must use the latest 1.7 version to export ant property to maven). 我通过ant和antrun插件直接使用p4可执行文件获得此修订号(您必须使用最新的1.7版本将ant属性导出到maven)。 You also need to have p4 executable available. 您还需要有可用的p4可执行文件。

After this plugin configuration is used you have ${revision.number} available in maven. 使用此插件配置后,您可以在maven中使用$ {revision.number}。

<!-- Get Perforce latest change number -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.7</version>
    <dependencies>
        <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
        </dependency>
    </dependencies>
    <configuration>
        <exportAntProperties>true</exportAntProperties>
    </configuration>
    <executions>
        <execution>
            <phase>validate</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <target>
                    <taskdef resource="net/sf/antcontrib/antcontrib.properties" classpath="maven.plugin.classpath"/>
                    <!-- Login to p4 -->
                    <exec executable="p4" inputstring="${p4.password}">
                        <arg value="-p${p4.server}"/>
                        <arg value="-c${p4.client}"/>
                        <arg value="-u${p4.username}"/>
                        <arg value="login"/>
                    </exec>
                    <!-- Get reivision description text -->
                    <exec executable="p4" outputproperty="revision.description">
                        <arg value="-p${p4.server}"/>
                        <arg value="-c${p4.client}"/>
                        <arg value="-u${p4.username}"/>
                        <arg value="changes"/>
                        <arg value="-m1"/>
                        <arg value="//...#have"/>
                    </exec>
                    <!-- Logout from p4 -->
                    <exec executable="p4">
                        <arg value="-p${p4.server}"/>
                        <arg value="-c${p4.client}"/>
                        <arg value="-u${p4.username}"/>
                        <arg value="logout"/>
                    </exec>

                    <!-- Parse revision description to retrieve only revision number -->
                    <propertyregex property="revision.number"
                                   input="${revision.description}"
                                   regexp="Change ([0-9]*) on ([a-z,0-9]*)"
                                   select="\1"
                                   casesensitive="false"/>

                    <echo>Perforce latest revision number: ${revision.number}</echo>
                </target>
            </configuration>
        </execution>
    </executions>
</plugin>

It's been a few years since the question was asked, but in the interval p4maven has been rewritten, and the updated documentation is startlingly hard to find. 问题问题已经过去了几年,但是在间隔p4maven被重写之后,更新的文档很难找到。

Here's the new README.md . 这是新的README.md I followed it through and everything works. 我跟着它,一切正常。 At this point, 1.0.6 is the latest version in maven central . 此时,1.0.6是maven central的最新版本。

I discovered the source from a link on the Maven build number plugin page. 我从Maven内部版本号插件页面上的链接中发现了源代码。

I landed here while searching for solution of a similar issue "NO Configuration could be determinded" which i faced with Code Collaborator client with P4. 我在寻找类似问题的解决方案时登陆这里“我可以确定没有配置”,我面对的是Code Collaborator客户端与P4。 I ended up in uninstalling P4 client and reinstalling to get it working. 我最终卸载了P4客户端并重新安装以使其正常工作。

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

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