简体   繁体   English

Maven 3.0的“mvn release:perform”不喜欢不在git repo根目录下的pom.xml

[英]Maven 3.0's “mvn release:perform” doesn't like a pom.xml that isn't in its git repo's root directory

I have a question about Maven, the maven-release-plugin, git integration, pom.xml's, and having pom.xml's in subdirectories of the repo's local copy rather than in the root. 我有一个关于Maven,maven-release-plugin,git integration,pom.xml的问题,并且在repo的本地副本的子目录中而不是在根目录中有pom.xml。

Here's the setup: 这是设置:

  • I have a github account with a limited number of private repositories 我有一个github帐户,其中包含有限数量的私有存储库
  • I want to (am just learning to) use Maven to organize my builds/releases 我想(我只是学习)使用Maven来组织我的构建/发布
  • I might need to create many Maven "projects", several projects per git repository 我可能需要创建许多Maven“项目”,每个git存储库有几个项目
  • Each maven project requires a "pom.xml" to define its characteristics 每个maven项目都需要一个“pom.xml”来定义其特征
  • I can't, or at least it's not convenient to, put all project pom.xml files in the root of the git repository 我不能,或者至少不方便,将所有项目pom.xml文件放在git存储库的根目录中
  • So I end up with this folder layout for projects: 所以我最终得到了项目的文件夹布局:
    • git_repo_root_dir git_repo_root_dir
      • project_A folder project_A文件夹
        • pom.xml 的pom.xml
        • other_code other_code
      • project_B folder project_B文件夹
        • pom.xml 的pom.xml
        • other_code other_code
      • etc. 等等
      • ... ...
  • I can successfully go to directory git_repo_root_dir/project_A and do an "mvn release:prepare" 我可以成功进入目录git_repo_root_dir / project_A并执行“mvn release:prepare”
  • I fail with this step in git_repo_root_dir/project_A: "mvn release:perform" 我在git_repo_root_dir / project_A中执行此步骤失败:“mvn release:perform”
    • The problem seems to be that the git-tagged code is successfully checked out to git_repo_root_dir/project_A/target/checkout/project_A in preparation for the release build, but then after the checkout the "maven-release" plugin goes to directory git_repo_root_dir/project_A/target/checkout/. 问题似乎是git-tagged代码成功检出git_repo_root_dir / project_A / target / checkout / project_A以准备发布版本,但是在结账后“maven-release”插件转到目录git_repo_root_dir / project_A /目标/结帐/。 instead of git_repo_root_dir/project_A/target/checkout/project_A/. 而不是git_repo_root_dir / project_A / target / checkout / project_A /。 to do the actual build, and there's no way to tell the "maven-release" plugin to step into a subdirectory of the special tagged copy of the source before trying to mess with the pom.xml 做实际的构建,并且没有办法告诉“maven-release”插件在尝试弄乱pom.xml之前进入源的特殊标记副本的子目录
  • QUESTION: is there a way around this? 问题:有没有办法解决这个问题? Is there an option to somehow tell "mvn release:perform" to go to the subdirectory? 有没有选择以某种方式告诉“mvn release:perform”转到子目录?

Here's the actual error I get during this process: 这是我在此过程中遇到的实际错误:

[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]

Thanks. 谢谢。

This should do the trick: 这应该做的伎俩:

<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>

You can do it in the same way you normally tell Maven to run from a POM that's somewhere else : the -f option. 你可以像通常告诉Maven从其他地方的POM运行一样-f选项。 mvn --help describes it thusly: mvn --help如此描述:

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

To do that in a release, you just need to pass the appropriate option to the release plugin. 要在发行版中执行此操作,您只需将适当的选项传递给发布插件即可。 You can use the perform goal's "arguments" property to do that. 您可以使用执行目标的“arguments”属性来执行此操作。 This property just tells the release plugin some additional arguments to append to the mvn command it runs when doing the release. 此属性只是告诉release插件一些附加参数,以附加到它在执行发布时运行的mvn命令。 You can set it from the command line by appending -D arguments="-f path/to/pom" or set it permanently in the pom in the release plugin's configuration, something like 您可以通过附加-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>

The first thing is to understand git which has it's convention that every project has it's own repository. 首先要理解git,它具有每个项目都拥有自己的存储库的约定。 The next thing is that Maven has it's conventions and putting the pom.xml into the root of it's project is the most obvious one. 接下来的事情是Maven有它的约定,把pom.xml放到它的项目的根目录中是最明显的。 Furthermore you are trying to fight against Maven and i will predict that you will lose the combat and make your life not easy. 此外,你正试图与Maven作战,我预测你将失去战斗,让你的生活变得不容易。 If your projects A and B are related (same versio number or same release times) in some kind you should think about a multi-module build which results in a structure like this: 如果您的项目A和B是相关的(相同的版本号或相同的发布时间),您应该考虑一个多模块构建,这将产生如下结构:

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

and you can do a release of both projectA (better calling it a module) and module b in a single step from the root. 并且您可以从根目录一步发布projectA(更好地称之为模块)和模块b。

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

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