简体   繁体   English

Maven版本:与Perforce一起执行不会创建target / checkout目录

[英]maven release:perform with Perforce does not create target/checkout directory

I can not make the maven-release plugin work with Perforce. 我无法使maven-release插件与Perforce一起使用。 The release:prepare seems to work correctly: a Perforce label is created and it contains the correct files. release:prepare似乎可以正常工作:创建了Perforce标签,其中包含正确的文件。 Yet when I run release:perform it fails because the target/checkout directory is empty. 但是,当我运行release:perform时,它失败了,因为target / checkout目录为空。

I've done some experiments. 我做了一些实验。 If I only sync to my pom.xml and then run mvn scm:checkout then my other files are checked out into the P4 root directory just as if I had done a p4 sync ... Yet Maven outputs [INFO] Checkout working directory: /home/chris/perforce/pips/target/checkout [INFO] sync -f //depot/pips/... Maven thinks it's checking out the target/checkout but it is not. 如果我仅同步到pom.xml,然后运行mvn scm:checkout,则将我的其他文件检出到P4根目录中,就像执行了p4同步一样……但是Maven输出[INFO] Checkout工作目录: / home / chris / perforce / pips / target / checkout [INFO] sync -f // depot / pips / ... Maven认为它正在签出目标/签出,但不是。 I dug into the P4Maven code a little bit and noticed this in P4Executor.java 我稍微研究了P4Maven代码,并在P4Executor.java中注意到了这一点。

public String getRepoPath(P4ScmProviderRepository repo, File basedir) {
    // Handles a case where executing release:prepare on a module with an
    // invalid SCM location. The release.properties contains the invalid URL
    // for checkout during release:perform and the basedir is not the module
    // root. So, the trailing target/checkout directory must be removed.
    if (basedir.toString().replace('\\', '/').endsWith("/target/checkout")) {
        String dir = basedir.toString();
        basedir = new File(dir.substring(0, dir.length()
                - "/target/checkout".length()));
        if (getLogger().isDebugEnabled()) {
            logger.debug("Fixing checkout URL: " + basedir);
        }
    }

This code is pretty clear. 这段代码很清楚。 P4Maven won't check things out to target/checkout. P4Maven不会将内容签出至目标/签出。 If you tell it to checkout to target/checkout it will simply remove the "target/checkout" and checkout to the root directory. 如果您告诉它检出到目标/检出,它将仅删除“ target / checkout”并检出到根目录。 This is consistent with what I see being done. 这与我看到的完成工作是一致的。 I also see the "Fixing checkout URL" message when I run release:perform 当我运行release:perform时,我还看到“正在修复结帐URL”消息。

How then do people work around this? 人们如何解决这个问题?

Below is my pom.xml. 以下是我的pom.xml。 I am using Perforce Server version: P4D/LINUX26X86_64/2014.2/935585 (2014/09/16). 我正在使用Perforce Server版本:P4D / LINUX26X86_64 / 2014.2 / 935585(2014/09/16)。 p4d is running locally. p4d在本地运行。 Authentication is disabled and I don't need a password. 身份验证已禁用,我不需要密码。 Nexus 2.10.0-02 running locally. Nexus 2.10.0-02在本地运行。 Ubuntu Linux. Ubuntu Linux。 Maven 3.2.3 java 1.7.0_55 Maven 3.2.3 Java 1.7.0_55

Thanks. 谢谢。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.ap
ache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.icap</groupId>
  <artifactId>pips</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>pips</name>

  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <scm>
     <connection>scm:p4:192.168.1.8:1666://depot/pips</connection>
     <developerConnection>scm:p4:192.168.1.8:1666://depot/pips</developerConnection>
  </scm>

  <build>
    <plugins>

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

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.1</version>
        <dependencies>
          <!-- P4Maven -->
          <dependency>
            <groupId>com.perforce</groupId>
            <artifactId>p4maven</artifactId>
            <version>[2011,2012)</version>
          </dependency>
        </dependencies>
        <configuration>
          <connectionType>connection</connectionType>
          <username>chelck</username>
          <includes>**</includes>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.2</version>
        <configuration>
          <fork>true</fork>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
      <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
      </dependency>
  </dependencies>

<distributionManagement>
  <repository>
     <id>deployment</id>
     <name>Internal Releases</name>
     <url>http://localhost:8081/nexus/content/repositories/releases/</url>
  </repository>
  <snapshotRepository>
     <id>deployment</id>
     <name>Internal Releases</name>
     <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>
</project>

I have struggled for several days on perforce / maven / release integration and finally got it working. 我在perforce / maven / release集成上苦苦挣扎了几天,终于使它工作了。 Here are my findings, they might help you and others with similar issues. 这是我的发现,它们可能会帮助您和其他遇到类似问题的人。

  1. Do not use the perforce plugin as described on perforce.com ( http://www.perforce.com/perforce/r11.1/manuals/p4maven/index.html ). 不要按照perforce.comhttp://www.perforce.com/perforce/r11.1/manuals/p4maven/index.html所述使用perforce插件 Although it is the first link to come out of a search on google, my understanding is that this plugin is outdated. 尽管这是从Google搜索获得的第一个链接,但我的理解是该插件已过时。

In your configuration, if you refer to scm:p4:... you are using the com.perforce plugin. 在您的配置中,如果您引用scm:p4:... ,则使用的是com.perforce插件。 Instead, use org.apache.maven.scm/maven-scm-provider-perforce which uses scm:perforce:... syntax. 而是使用org.apache.maven.scm / maven-scm-provider-perforce,该语法使用scm:perforce:...语法。 Your <scm> should look like this: 您的<scm>应该如下所示:

<properties>
  <p4path>//perforce-path/toyour/project</p4path>
</properties>

<scm>
  <connection>scm:perforce:yourp4server:1666:${p4path}</connection>
  <developerConnection>scm:perforce:yourp4server:1666:${p4path}</developerConnection>
  <url>perforce:yourp4server:1666:${p4path}</url>
</scm>

The newer plugin does not require username/password, it will use your active P4 credentials. 较新的插件不需要用户名/密码,它将使用您的有效P4凭据。

I am using maven 3.2.5 and did not have to specify any plugin dependency. 我正在使用maven 3.2.5,而不必指定任何插件依赖项。 The built-in scm recognized the :perforce: scm and downloaded maven-scm-provider-perforce 1.9.2 which is the latest as of this writing. 内置的scm可以识别:perforce: scm并下载了maven-scm-provider-perforce 1.9.2,这是撰写本文时的最新版本。 You can make sure you are using an up to date plugin by deleting the maven-scm-provider-perforce folder in .m2\\repository\\org\\apache\\maven\\scm and then doing a mvn scm:status - it will download the missing plugin and you can see which one it picked. 您可以通过删除.m2 \\ repository \\ org \\ apache \\ maven \\ scm中的maven-scm-provider-perforce文件夹,然后执行mvn scm:status来确保使用的是最新插件,它将下载缺少的文件插件,您可以看到它选了哪一个。

Here is my maven-release-plugin definition: 这是我的maven-release-plugin定义:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
        <version>2.5.1</version>
    </plugin>

I do not have a maven-scm-plugin definition in my pom (I used the default settiings from the superpom). 我的pom中没有maven-scm-plugin定义(我使用了superpom中的默认设置)。

  1. Test on a non-module project. 在非模块项目上测试。

You should be able to do the following without error: - mvn scm:status to check that your scm setup is working correctly - mvn release:prepare - mvn release:perform 您应该能够执行以下操作而不会出现错误: mvn scm:status检查您的scm设置是否正常工作mvn release:prepare mvn release:perform

If you get errors, rollback ( mvn release:rollback ), make sure everything is back to normal, and rerun with mvn -X to get more details. 如果遇到错误,请回滚( mvn release:rollback ),确保一切恢复正常,然后使用mvn -X重新运行以获取更多详细信息。

In my case, a non-modular project worked without much trouble. 以我为例,一个非模块化项目的工作没有太多麻烦。

  1. Test on the parent of a reactor project. 在反应堆项目的父项上进行测试。

There are a few things that were not obvious to me at first and that I found out: 一开始我发现的一些不明显的事情是:

  • When the is defined in the parent pom, the child module name gets appended to the path for the child module . 在父pom中定义时,子模块名称将附加到子模块的路径 If your child is not physically under the parent (in my case, it was beside), you need to redefine a configuration in the child pom. 如果您的孩子不在父母的监护下(在我的情况下是在旁边),则需要在子pom中重新定义配置。 In my case, I was using a property (p4path above), simply changing its value was not enough. 就我而言,我使用的是属性(上面的p4path),仅更改其值是不够的。 This was counter-intuitive since the parent pom is normally just a "include", and I expected the parent definitions to be "copy-pasted" in the child module, but in this particular case, it is modified to include the module name at the end of the scm path when it is copy-pasted. 这是违反直觉的,因为父pom通常只是一个“ include”,我希望父定义在子模块中被“复制粘贴”,但是在这种特殊情况下,它被修改为在以下位置包含模块名称复制粘贴时scm路径的末尾。 [ More on modules that do not sit under the parent directory below ] [ 有关不位于下面父目录下的模块的更多信息 ]

  • A temporary client spec is created by the perforce scm plugin . 临时客户端规范是由perforce scm插件创建的 This was also counter intuitive, I expected the scm plugin to use my current client-spec. 这也很直观,我希望scm插件使用我当前的客户端规范。 Instead, it will create a new one on the fly, and populate it with the path you provided only and name it username-hostname-MavenSCM-localpath . 相反,它将动态创建一个新文件,并使用仅提供的路径填充它,并将其命名为username-hostname-MavenSCM-localpath I was initially surprised by that and tried to change it so it would use by client-spec by customizing the maven.scm.perforce.clientspec.name property, this behaviour was actually correct. 最初,我对此感到惊讶,并尝试对其进行更改,以便通过定制maven.scm.perforce.clientspec.name属性由客户端规范使用,这种行为实际上是正确的。 With this temporary client-spec, the plugin can limit the lookup for changes, the submit and tagging to this directory. 使用此临时客户端规范,插件可以限制对更改的查找,提交和标记到该目录。 It also makes it easy to track what was done by this plugin in the perforce history. 它还使在perforce历史记录中轻松跟踪此插件的操作。

  • Creation of the temporary client spec will fail if the modules are not under the parent directory . 如果模块不在父目录下,则创建临时客户端规范将失败 As I described above, my modules were sitting beside the parent. 如上所述,我的模块位于父级旁边。 My <module> tag in the parent pom referred to them using <module>../mymodule</module> which worked fine in eclipse for everything else. 我在父pom中的<module>标记使用<module>../mymodule</module>引用了它们,在eclipse中,其他所有内容都可以正常工作。 The scm perforce plugin includes modules in the client spec by appending the path to the module to the path of the parent. scm perforce插件通过将模块的路径附加到父级的路径来在客户端规范中包括模块。 Since Maven resolves the ../ to an absolute path, the client spec ends up containing something like this: //perforce-path/toyour/project/C:\\Path\\To\\Your\\Project/mymodule/ and the client spec fails. 由于Maven将../解析为绝对路径,因此客户端规范最终包含以下内容: //perforce-path/toyour/project/C:\\Path\\To\\Your\\Project/mymodule/并且客户端规范失败。 I could not find a work around for this issue other than moving my modules under their parent. 除了将模块移到其父级下之外,我无法找到解决该问题的方法。 Since the client spec was invalid, I had no file being checked-out under target/checkout. 由于客户端规范无效,因此我没有在目标/签出下签出文件。 You will get the content of your generated client spec on the console by using mvn -X when invoking release:perform . 调用release:perform时,将使用mvn -X在控制台上获得生成的客户端规范的内容。

Moral of the story : You want to make sure that all your modules sit under their parent directory. 故事的寓意 :您想确保所有模块都位于其父目录下。 When you do this, everything becomes simple and magical: you can leave the declaration in your parent pom and the module path gets magically appended for the module scm paths. 当执行此操作时,一切变得简单而神奇:可以将声明保留在父pom中,并且将模块路径神奇地附加到模块scm路径。 You can refer to your modules using <module>mymodule</module> which gets correctly appended in the client-spec. 您可以使用<module>mymodule</module>引用您的模块,该<module>mymodule</module>正确附加在客户端规范中。 Tagging of the parent in perforce ends up also tagging the modules since they are contained within. 由于在perforce中标记了父模块,因此它们最终也将对其进行标记。

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

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