19

Maven は 3.1.0 です。

プロジェクトの pom.xml で versions-maven-plugin:2.2 を使用しています (以下を参照)。通常の pom.xml ファイル構成とは別に、メイン コードのスナップショットを以下に示します。

<project
  xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>tools-parent</artifactId>
    <version>0.0.7-SNAPSHOT</version>
    <packaging>pom</packaging>

    <description>
        Infrastructure related to the &quot;vapp&quot; and
        &quot;deployer&quot; utilities.
    </description>

    <parent>
        <groupId>com.company.product</groupId>
        <artifactId>deploy-parent</artifactId>
        <version>0.0.6-SNAPSHOT</version>
    </parent>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-scm-plugin</artifactId>
                <version>1.9.4</version>
                <configuration>
                    <connectionType>connection</connectionType>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-enforcer-plugin</artifactId>
                <version>1.4</version>
                <executions>
                    <execution>
                        <!-- Make sure that only non-snapshot versions are used for the dependencies. Only active when property 'snapshotDependencyAllowed' is false. -->
                        <id>enforce-no-snapshots</id>
                        <goals>
                            <goal>enforce</goal>
                        </goals>
                        <configuration>
                            <skip>${snapshotDependencyAllowed}</skip>
                            <rules>
                                <requireReleaseDeps>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseDeps>
                                <requireReleaseVersion>
                                    <message>No Snapshots Allowed!</message>
                                </requireReleaseVersion>
                            </rules>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

mvn clean installを実行すると、正常にビルドされます。

:私のプロジェクトには、グループID「com.company.product」が同じグループIDである展開親アーティファクトに依存している親セクションがあります。上に貼り付けました)が、展開親は別のリポジトリ/プロジェクトの成果物です。

mvn versions:set -DnewVersion=0.0.7を実行すると、次のエラー メッセージが表示されます。

[INFO] ------------------------------------------------------------------------
[INFO] Building tools-parent 0.0.7-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- versions-maven-plugin:2.2:set (default-cli) @ tools-parent ---
[INFO] Searching for local aggregator root...
[INFO] Local aggregation root: /user/home/u100123/giga/tools
[INFO] Processing change of com.company.product:tools-parent:0.0.7-SNAPSHOT -> 0.0.7
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] tools-parent .................................... FAILURE [1.093s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.404s
[INFO] Finished at: Fri May 01 20:44:22 GMT-00:00 2015
[INFO] Final Memory: 12M/246M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:versions-maven-plugin:2.2:set (default-cli) on project tools-parent: Execution default-cli of goal org.codehaus.mojo:versions-maven-plugin:2.2:set failed. NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

今、versions-maven-plugin バージョンを 2.1 (以前に使用していたもの) に戻すと、上記のmvn versions:set -DnewVersion=0.0.7コマンドが正常に機能し、pom.xml ファイルが正常に変更されます。<version>0.0.7</version>ツールの親アーティファクト用。

バージョン 2.2 では、エラーが発生し、バージョンが 0.0.7 に変更されません。

  1. 2.2 が失敗する理由はありますか? それを解決するために何ができますか?
4

4 に答える 4

31

何かのバグのようです。

解決策:

1 . <groupId>com.company.product</groupId>... セクションの外にもプロパティ追加する必要があります。つまり、tools-parent、NOW version-maven-plugin の場合: 2.2は正常に動作しています。つまり、一番上の行を追加しました (以下を参照)。唯一のことは、親セクションの使用は何ですか(デプロイ親がツール親プロジェクトにもたらすもののメインコードを継承することは別として)。groups-maven-plugin:2.2 が正常に機能するために、artifactId tools-parent の親セクションの出力を groupId で定義する必要があるのはなぜですか。

最も重要なことは次のとおりです。この問題は、プロジェクト/モジュールのpom.xmlに<parent>、親セクションのartifactIdがプロジェクト自体の親ではないセクションがある場合にのみ発生します(典型的なMaven Uncleの状況)つまり、tools-parentの場合アーティファクトが別のモジュール (tools-child としましょう) の親セクションで定義されている場合、バージョン 2.2 は正常に動作します。ただし、tools-child の親セクションに「tools-parent」としての artifactId が含まれておらず、例: deploy-parent/some-different-project-artifact (ソース管理ツールの別のプロジェクトにある) の場合は別のものです。 、tools-child artifactId の場合、groupId値も親セクションの外に設定する必要があります ( groupId がセクションのartifactId は tools-child のgroupIdと同じ/異なります)。

<groupId>com.company.product</groupId>
<artifactId>tools-parent</artifactId>
<version>0.0.7-SNAPSHOT</version>
<packaging>pom</packaging>

<description>
    Infrastructure related to the &quot;vapp&quot; and
    &quot;deployer&quot; utilities.
</description>

<parent>
    <groupId>com.company.product</groupId>
    <artifactId>deploy-parent</artifactId>
    <version>0.0.6-SNAPSHOT</version>
</parent>

--または

2 . versions-maven-plugin: 2.1に戻します。

于 2015-05-01T21:17:51.117 に答える
18

Arun の回答のパート 2 に追加するだけで、バージョン 2.1 のプラグインを使用する方法は次のとおりです。

mvn org.codehaus.mojo:versions-maven-plugin:2.1:set org.codehaus.mojo:versions-maven-plugin:2.1:commit -DnewVersion=0.0.7

完全なグループ ID とアーティファクト ID を指定する必要があります。

于 2015-07-10T01:18:22.210 に答える
3

この問題について報告されたこのバグを見つけました:

https://github.com/mojohaus/versions-maven-plugin/issues/51

于 2015-05-01T21:35:15.937 に答える
2

私も NPE に遭遇しましたが、その理由は以前に示唆されたものとは別のものであることがわかりました。<version>versions-maven-plugin をデバッグしたところ、NPE はにリストされている依存関係の宣言が欠落していることが原因であることがわかりました<dependencyManagement>。これは、次のリストで再現できます。

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>npe</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>NPE Example</name>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <!-- missing <version>4.2.0.RELEASE</version> -->
                <scope>runtime</scope>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.0.RELEASE</version>
        </dependency>
    </dependencies>
</project>
于 2015-08-31T08:54:59.930 に答える