9

我有一个关于 Maven、maven-release-plugin、git 集成、pom.xml 以及在 repo 本地副本的子目录中而不是在根目录中的 pom.xml 的问题。

这是设置:

  • 我有一个私人存储库数量有限的 github 帐户
  • 我想(正在学习)使用 Maven 来组织我的构建/发布
  • 我可能需要创建许多 Maven “项目”,每个 git 存储库有几个项目
  • 每个 maven 项目都需要一个“pom.xml”来定义它的特性
  • 我不能,或者至少不方便,将所有项目 pom.xml 文件放在 git 存储库的根目录中
  • 所以我最终得到了这个项目的文件夹布局:
    • git_repo_root_dir
      • project_A文件夹
        • pom.xml
        • 其他代码
      • project_B文件夹
        • pom.xml
        • 其他代码
      • 等等
      • ...
  • 我可以成功进入目录 git_repo_root_dir/project_A 并执行“mvn release:prepare”
  • 我在 git_repo_root_dir/project_A 中的这一步失败了:“mvn release:perform”
    • 问题似乎是 git-tagged 代码已成功签出到 git_repo_root_dir/project_A/target/checkout/project_A 以准备发布构建,但是在签出之后“maven-release”插件进入目录 git_repo_root_dir/project_A /目标/结帐/。而不是 git_repo_root_dir/project_A/target/checkout/project_A/。进行实际构建,并且在尝试弄乱 pom.xml 之前,无法告诉“maven-release”插件进入源的特殊标记副本的子目录
  • 问题:有没有办法解决这个问题?是否可以选择以某种方式告诉“mvn release:perform”转到子目录?

这是我在此过程中遇到的实际错误:

[INFO] --- maven-release-plugin:2.0:perform (default-cli) @ standard_parent_project ---
[INFO] Checking out the project to perform the release ...
[INFO] Executing: /bin/sh -c cd "/Users/___/DEV c8ion 01/maven_based_code/0maven/standard_parent_project/target" && git clone git@github.com:clarafaction/0maven.git '/Users/___/DEV c8ion 01/maven_based_code/0maven/standard_parent_project/target/checkout'
...
/* note, the pom.xml the build should go out of at this point is at
   '/Users/___/DEV c8ion 01/maven_based_code/0maven/standard_parent_project/target/checkout/standard_parent_project/pom.xml'
*/
...
[INFO] [ERROR] The goal you specified requires a project to execute but
    there is no POM in this directory
    (/Users/___/DEV c8ion 01/maven_based_code/0maven/standard_parent_project/target/checkout).
    Please verify you invoked Maven from the correct directory. -> [Help 1]

谢谢。

4

3 回答 3

11

这应该可以解决问题:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.3.2</version>
    <executions>
        <execution>
            <id>default</id>
            <goals>
                <goal>perform</goal>
            </goals>
            <configuration>
                <pomFileName>your_path/your_pom.xml</pomFileName>
            </configuration>
        </execution>
    </executions>
</plugin>
于 2012-10-11T14:42:26.350 回答
7

您可以按照通常告诉 Maven 从其他地方的 POM 运行的相同方式执行此操作:-f选项。mvn --help如此描述它:

-f,--file <arg>    Force the use of an alternate POM
                   file.

要在发布中做到这一点,您只需将适当的选项传递给发布插件。您可以使用执行目标的“参数”属性来执行此操作。这个属性只是告诉发布插件一些额外的参数来附加到mvn它在发布时运行的命令。-D arguments="-f path/to/pom"您可以通过在发布插件配置的 pom 中附加或永久设置它来从命令行设置它,例如

<plugin>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <arguments>-f path/to/pom</arguments>
    </configuration>
</plugin>
于 2012-05-22T03:24:00.487 回答
-2

首先要了解 git,它的约定是每个项目都有自己的存储库。接下来的事情是 Maven 有它的约定,将 pom.xml 放到它的项目的根目录中是最明显的。此外,您正试图与 Maven 对抗,我预测您将输掉这场战斗,让您的生活变得不轻松。如果您的项目 A 和 B 在某种程度上是相关的(相同的版本号或相同的发布时间),您应该考虑一个多模块构建,它会产生如下结构:

root (Git Repos)
  +-- pom.xml
       +--- projectA (pom.xml)
       +--- projectB (pom.xml)

并且您可以从根目录一步完成 projectA(最好称其为模块)和模块 b 的发布。

于 2012-05-22T06:29:00.303 回答