English 中文(简体)
马文 3. 0 s "mvn resent: performorporation" 不喜欢 在其 git repo s root 目录中的 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

我有一个关于马文的问题, maven- release- plutin, git 集成, pom.xml s, 和pom.xmls, 并且有 pom.xmls 在 当地副本的子目录中, 而不是根。

这里的设置 :

  • I have a github account with a limited number of private repositories
  • I want to (am just learning to) use Maven to organize my builds/releases
  • I might need to create many Maven "projects", several projects per git repository
  • Each maven project requires a "pom.xml" to define its characteristics
  • I can t, or at least it s not convenient to, put all project pom.xml files in the root of the git repository
  • So I end up with this folder layout for projects:
    • git_repo_root_dir
      • project_A folder
        • pom.xml
        • other_code
      • project_B folder
        • pom.xml
        • other_code
      • etc.
      • ...
  • I can successfully go to directory git_repo_root_dir/project_A and do an "mvn release:prepare"
  • I fail with this step in 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/. instead of 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
  • QUESTION: is there a way around this? Is there an option to somehow tell "mvn release:perform" to go to the subdirectory?

在此列出在此过程中我得到的实际错误 :

[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 [email protected]: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]

谢谢

问题回答

这应该能把戏:

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

您可以用通常的的同样方式进行操作。 http://www. sonatype.com/book/mvnref-book/review/transing- section- particle- options.html#running- control- custom- place- options" rel=“ norefererr”> >tell Maven, 以便从位于其他地方 的POM运行: -f 选项。 mvn-help 如此描述:

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

要在发布中做到这一点, 您只需要将合适的选项传递到发布插件 。 您可以使用 < a href=" http:// maven. apache. org/ plugins/ maven- release- plitin/ perform- mojo. html# arguments" rel= “ noreferrer” >perform target s “ arguments” 属性 来做到这一点。 此属性只是告诉发布插件一些附加参数, 以附加到发布时它运行的 < code> mvn 命令。 您可以在发布插件配置中附加 < code>- D参数=" - f path/to/pom " 或将其永久设置在 pom 中, 类似 。

<plugin>
    <artifactId>maven-release-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <arguments>-f path/to/pom</arguments>
    </configuration>
</plugin>

这个问题是在10多年前提出的,因此我想提供更最新的答案。

截至2022年10月,目前/现代马文在子目录中没有任何问题。maven插件的当前版本是

只需要您在 POM 中定义的正常元素 。 maven 发布插件需要 :

NOTE:也可以通过命令行通过这些参数,但我更希望将这些参数放入一个文件(pom.xml,为 ,或甚至设置.xml),以便更好地记录进程,使团队中的其他 deds更容易被部署。

NOTE:我在爪哇11中使用了3.8.5版马文版本,但AFAIK Java的版本并不重要。最新版本马文为3.8.6(此时此刻)。我相信这对爪哇8有效。此时,马文4在阿尔法。

How it works

Assumptions

在这一例子中,使用了以下方法:

Each of the apps or libraries are in a separate directory with no parent POM being used (in this example). So you can t type mvn clean install from the top level directory. This is similar to the original OP question. As one commenter said, this is type of problem happens in a polyglot repo where multiple languages and technologies are used.

Explanation of POM configuration needed

lib1 中, pom 定义如下( 仅显示 Maven 发布插件的设置 ) 。 < nuger> NOTE: 这是此仓库的所有 POM 中将包含的 < em> SAME 信息 。

    <scm>
        <connection>scm:[email protected]:user123/proj456.git</connection>
        <developerConnection>scm:[email protected]:user123/proj456.git</developerConnection>
        <tag>HEAD</tag>
    </scm>
    <distributionManagement>
        <downloadUrl>https://mynexus.example.com/repository/maven-public</downloadUrl>
        <repository>
            <id>proj456-release</id>
            <name>proj456 release distro</name>
            <url>https://mynexus.example.com/repository/proj456-release</url>
        </repository>
        <snapshotRepository>
            <uniqueVersion>true</uniqueVersion>
            <id>proj456-snapshot</id>
            <name>proj456 snapshot</name>
            <url>https://mynexus.example.com/repository/proj456-snapshot</url>
        </snapshotRepository>
    </distributionManagement>

注意: 您的设置. xml 文件需要包含您的登录或指定证书, 以便看起来像 :

    <servers>
        <server>
            <id>proj456-releases</id>
            <username>user123</username>
            <password>not-shown</password>
        </server>
        <server>
            <id>proj456-snapshot</id>
            <username>user123</username>
            <password>not-shown</password>
        </server>
    </servers>


当您对您正在制作的每个maven 文物有单独的 git repo 时, 每一个标记的 < code@ lt; scm> 标记将有所不同 。

Creating a release

使用正常的 Maven 释放命令, 仅来自子目录 :

cd $HOME/work/proj456
ls -1
app1
app2
lib1
lib2

# Now CD to the directory you want to create a release for
cd lib1
mvn release:clean
mvn release:prepare release:perform

At the end of this process, the maven release plugin will do all the things it normally does. For example,

  1. The -SNAPSHOT version in the POM is replaced with a release version (that you specify).
  2. A git commit is created with the release version.
  3. A maven build and package is created with that release.
  4. The maven package is pushed (uploaded) to the NEXUS repo (or maven central).
  5. The pom.xml is bumped to the next version (with -SNAPSHOT added) and git commit is made so future development occurs on next SNAPSHOT version.

See maven docs for maven release plugin for a complete list of the steps.

The first thing is to understand git which has it s convention that every project has it s own repository. 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. Furthermore you are trying to fight against Maven and i will predict that you will lose the combat and make your life not easy. 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:

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

并且您可以在根部的单步内发布项目A(更好地称它为模块)和模块b。





相关问题
JavaFX with Maven [closed]

I recently started a JavaFX project, and I d like to use Maven as my compiler/deployment tool. Is there a good tutorial or plugin to integrate JavaFX and Maven?

How to upload jar to respository?

I have jar files that cannot be found on Maven Central repository. I would like to add the jar so I can just include extra tag in my pom.xml file and other developer can use the jar. What are the ...

Debug Maven project in Eclipse with third party sources

I am currently developing a maven project in eclipse. The m2eclipse plugin works beautifully. It even works out of the box with debugging. But when I am debugging open source third party libarries. ...

Could Free Pascal benefit of something like Apache Maven?

Apache Maven is a very popular build and dependency management tool in the Java open source ecosphere. I did some tests to find out if it can handle compiled Free Pascal / Delphi units and found it ...

Run a single test method with maven

I know you can run all the tests in a certain class using: mvn test -Dtest=classname But I want to run an individual method and -Dtest=classname.methodname doesn t seem to work.

Uploading a directory using sftp with Maven

How can I upload a directory - Eclipse update site - using sftp with public key authentication in Maven? For background information: I m using tycho to build an Eclipse plugin and want to get the ...

What are solid NMaven or build servers for .NET alternatives?

Maven had a long history and is well supported in the Java world. NMaven has received a less successful start and has never become as popular in the C#/.NET world as its larger cousin was in the Java ...

热门标签