3

プロジェクトのマニフェストにSVNリビジョン番号を追加しようとしています。そのために、Mavenビルド番号プラグインを使用して、SuperPOMに次の行を追加しました。

<!-- Gets the SVN revision number -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>create</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <doCheck>false</doCheck>
                <doUpdate>false</doUpdate>
                <providerImplementations>
                    <svn>javasvn</svn>
                </providerImplementations>
            </configuration>
        </plugin>
        <!-- Add the SVN revision number in the manifest (works on Hudson only) -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <archive>
                    <manifest>
                        <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                    </manifest>
                    <manifestEntries>
                        <Implementation-Build>${buildNumber}</Implementation-Build>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>

構成に注意してください。

<doCheck>false</doCheck>
<doUpdate>false</doUpdate>

ローカルで変更を加えた場合、「doCheck」を使用するとコンパイルできなくなるため、意図的にこれを行いました(そして、作業をコミットする前にコンパイルしてテストしたいと思います)。

「doUpdate」も私にとって問題です。リポジトリからコードを更新する必要は必ずしもないからです。上記と同じ理由で、コミットする(そして潜在的に競合を解決する)前にローカルでテストしたいと思います。

私の問題は、マニフェストに表示されるのは次のとおりです。

Implementation-Build: ${buildNumber}

したがって、変数は解釈されません。私は何を取りこぼしたか?

ありがとう

編集: 問題は実際にはmaven-bundle-pluginにあります。私はこれをプロジェクトで使用してOSGiバンドルを生成します。

したがって、プロジェクトのPOMパッケージは次のようになります。

<packaging>bundle</packaging>

それ以外の:

<packaging>jar</packaging>

これはMavenのライフサイクルを台無しにしていると思います。maven-bundle-pluginを削除すると、すべてが正常に機能します。しかし、私のアプリケーションはOSGiアプリであるため、削除できません。

4

3 に答える 3

1

問題は、maven-bundle-plugin と maven-jar-plugin を混合して Jar MANIFEST を操作することでした。

ソリューション:

スーパー POM では:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Implementation-Build>${buildNumber}</Implementation-Build>
                    </instructions>
            </configuration>
            </plugin>
            ...
        </plugins>
    </pluginManagement>
    <plugins>
        <!-- Gets the SVN revision number -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>buildnumber-maven-plugin</artifactId>
            <version>1.1</version>
            <executions>
                <execution>
                <phase>validate</phase>
                <goals>
                <goal>create</goal>
                </goals>
            </execution>
            </executions>
            <configuration>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <providerImplementations>
                <svn>javasvn</svn>
            </providerImplementations>
            </configuration>
        -</plugin>
    </plugins>
</build>

以上です!

于 2012-10-05T09:43:59.327 に答える
0

Maven Plugin Managementを利用できます。

<pluginManagement/>次のように、super pom の下にプラグイン定義を追加します。

<project>
    ...
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>buildnumber-maven-plugin</artifactId>
                    <version>1.1</version>
                    <executions>
                        <execution>
                            <phase>validate</phase>
                            <goals>
                                <goal>create</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <doCheck>false</doCheck>
                        <doUpdate>false</doUpdate>
                        <providerImplementations>
                            <svn>javasvn</svn>
                        </providerImplementations>
                    </configuration>
                </plugin>
                <!-- Add the SVN revision number in the manifest (works on Hudson only) -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.1</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
                            </manifest>
                            <manifestEntries>
                                <Implementation-Build>${buildNumber}</Implementation-Build>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    ...
</project>

次に、これらの構成済みプラグインを使用するプロジェクトで、これを poms に追加します。

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>buildnumber-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    ...
</project>

それはあなたのためにそれを整理するはずです。

于 2012-09-26T18:36:20.257 に答える