13

Maven と Findbugs プラグインを使用して、複数のプロジェクトをセットアップしました。子プロジェクトの 1 つでいくつかのファイルを除外する必要があるため、に追加しましたfindbugs-exclude.xml。サブプロジェクトでビルドすると機能します。

トップレベルでビルドしようとすると、私の問題が発生します。findbugs-exclude.xmlサブプロジェクトでMaven が見つかりません。したがって、エラーが無視されず、エラーが原因で失敗します。findbugs-exclude.xml最上位ディレクトリに配置すると、除外が機能します。しかし、それはトップレベルを汚すものであり、好意的に見られることはありません。

findbugs-exclude.xmlサブディレクトリからファイルを使用するように Maven プラグインを取得する方法はありますか? できれば、トップ レベルでほとんどまたはまったく変更しないでください。

4

5 に答える 5

4

これに対する 1 つの解決策は、findbugs-excludes.xml を含む別のプロジェクトを作成し、依存関係プラグインを使用して解凍し、次のように必要な場所にローカルに配置することです。

<profile>
    <id>static-analysis</id>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-findbugs</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.myproject</groupId>
                                    <artifactId>my-findbugs</artifactId>
                                    <version>0.1-SNAPSHOT</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>src/main/findbugs/</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                            <!-- other configurations here -->
                            <excludes>META-INF/</excludes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <configuration>
                    <xmlOutput>true</xmlOutput>
                    <!-- Optional directory to put findbugs xdoc xml report -->
                    <xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
                    <effort>Max</effort>
                    <threshold>Low</threshold>
                    <excludeFilterFile>src/main/findbugs/findbugs-excludes.xml</excludeFilterFile>
                </configuration>
                <executions>
                    <execution>
                        <id>findbugs-run</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</profile>

このアプローチを使用すると、必要に応じてこの除外ファイルをプロジェクト間で共有できます。これは、見方によっては良いことも悪いこともあります:)また、考えてみると、専用のfindbugsプロジェクトがある場合は、さまざまなフレーバーを作成できます分類子を使用して除外を設定し、コンテキストに応じて特定の分類子を使用します。完璧ではありませんが、私にとってはうまくいきます。

HTH、ジェームズ

于 2010-12-09T10:57:40.080 に答える
3

現在のプロジェクトで私が行っていることはfindbugs-exclude.xml次のとおりです。親プロジェクトに入れますが (これは望ましくないことはわかっています)、2 つの場所で維持するという DRY 問題を修正します。アンパックよりも簡単ですが、プロジェクト構造全体がローカルである必要があります。(解凍ソリューションは、企業環境のように、多くのプロジェクトで同じ構成を使用するのに役立つと思います。)

私は findbugs 設定を に保存していますparent/src/main/resources/shared/findbugs-exclude.xmlが、それが親にある限り、特定のディレクトリは関係ありません。

次に、プロパティを使用して「共有」ディレクトリの場所を記述します。

<properties>
  <myproject.parent.basedir>${project.parent.basedir}</myproject.parent.basedir>
  <myproject.parent.shared.resources>${myproject.parent.basedir}/src/main/resources/shared</myproject.parent.shared.resources>
</properties>

親で findbugs を構成するときに、これらのプロパティを参照します。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <configuration>
      <excludeFilterFile>${myproject.parent.shared.resources}/findbugs-exclude.xml</excludeFilterFile>
    </configuration>
    ...
</plugin>

直接の子プロジェクトはすべて、親の構成ファイルを参照して findbugs を実行するようになりました。複数レベルのプロジェクトの入れ子がある場合はmyproject.parent.basedir、サブ親で をオーバーライドする必要があります。たとえば、親 <- サブ親 <- 子がある場合、次のように入力します。

<properties>
    <myproject.parent.basedir>${project.parent.parent.basedir}</myproject.parent.basedir>
</properties>
于 2011-07-22T16:22:15.097 に答える
0

受け入れられた回答に代わるより良い方法は、maven-remote-resources-pluginを使用することです。James のアプローチは気に入っていますが、クリーン プラグインを微調整して、src フォルダー内の解凍されたファイルを削除する必要があります。

James の提案に従って、findbugs-excludes.xml を含む別のプロジェクトを作成し、その pom ファイルに以下を追加します。

  <build>
    <plugins>
        <plugin>
            <artifactId>maven-remote-resources-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <goals>
                        <goal>bundle</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <includes>
                    <include>**/*.*</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

findbugs プラグインを含む pom ファイルを更新します。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-remote-resources-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <id>process-remote-resources</id>
            <goals>
                <goal>process</goal>
            </goals>
            <configuration>
                <resourceBundles>
                    <resourceBundle>com.myproject:myartifactid:version</resourceBundle>
                </resourceBundles>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>findbugs-maven-plugin</artifactId>
    <configuration>
        ...
        ...
        <excludeFilterFile>${project.build.directory}/maven-shared-archive-resources/findbugs-exclude.xml</excludeFilterFile>
        ...        
    </configuration>
</plugin>

com.myproject:myartifactid:versionを変更することを忘れないでください

maven-remote-resources-plugin は共有ファイルをターゲット フォルダーにコピーするため、maven-clean-plugin のデフォルトの動作を変更する必要はありません。

于 2016-07-15T02:25:56.817 に答える