6

我正在将一个项目迁移到 Maven,并且由于我们习惯于始终通过 Perforce SCM 存储库中的最新更改号来引用我们的构建,我希望能够提取此信息

我正在尝试通过以下资源配置 Maven scm 插件:

首先,我不明白如何使它工作,所以如果有人有一个完全工作的例子,我会很高兴,在我这边,我尝试通过添加我的 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>

这导致我:

[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

肯定忘记了什么,我会尝试再次阅读说明,看看我错过了什么,但如果有人知道......

无论如何,我的问题是:值得尝试吗?我在 scm 插件的可用操作中没有看到任何可以帮助我获取最新更改信息并将其集成到参考内部版本号中的内容。我应该为此开发自己的插件吗?

提前致谢。

4

4 回答 4

2

我从一位 P4Maven 开发人员那里得到了一些可能会有所帮助的建议。

首先,检查您的配置。“”标签中的“...”应该是“”标签中的标签名称之一(即“connection”或“developerConnection”)

有两个选项可以将 Maven 与 Perforce SCM 一起使用。

  1. 使用默认(内置)Maven Perforce SCM 提供程序(基于 p4 命令行)

    • 请注意,您需要安装 p4 命令行可执行文件
    • 您可以使用环境变量或 JVM args 设置用户名和密码

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

或者

[JVM 参数] -Dusername= -Dpassword=

[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. 使用 P4Maven Perforce SCM 提供程序(基于 P4Java)

[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

...

  • 请注意,对于 P4Maven,我们将覆盖“maven-scm-plugin”插件中的默认提供程序。

  • 请注意,我们使用“scmp4”(如果使用 P4Maven)而不是“scmperforce”(内置默认)作为提供程序名称,因为现有默认实现采用“perforce”。

于 2012-03-28T19:06:50.970 回答
1

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). I checked buildnumber-maven-plugin, but it does not support Perforce at all. 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.

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). You also need to have p4 executable available.

After this plugin configuration is used you have ${revision.number} available in maven.

<!-- 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>
于 2012-04-26T09:20:29.800 回答
0

我在寻找类似问题的解决方案时来到这里,我遇到了带有 P4 的 Code Collaborator 客户端。我最终卸载了 P4 客户端并重新安装以使其正常工作。

于 2016-07-13T09:28:58.720 回答
0

问这个问题已经有几年了,但在此期间 p4maven 已被重写,并且更新的文档非常难以找到。

这是新的README.md。我遵循了它,一切正常。此时,1.0.6 是maven central中的最新版本。

我从 Maven 内部版本号插件页面上的链接中发现了源代码。

于 2016-06-01T21:10:09.780 回答