3

アニマル スニファーを使用して、1 つのクラスと 1 つのメソッドのみを含む独自の API に対してクラスをチェックしたいと考えています。

package sniffertestapi;

public class MainInterface
{
    public static void testMethod(String testString)
    {
        System.out.println(testString);
    }
}

プロジェクトのビルドには、次の単純な POM が使用されます。

<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>TestAPI</groupId>
    <artifactId>TestAPI</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <version>1.13</version>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <javaHome>C:\Program Files\Java\jdk1.7.0_51</javaHome>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

ビルドは正常に実行され、TestAPI-0.0.1-SNAPSHOT.signature と jar が私の maven リポジトリにインストールされます。

次に、依存関係として TestAPI を追加しtestMethod、別のプロジェクトの を使用します。

package sniffertest;

import sniffertestapi.MainInterface;

public class Tester
{
    public Tester()
    {
        MainInterface.testMethod("Hi");
    }
}

このプロジェクトでは、別の目的で動物スニファー プラグインを追加しました。

<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>TestTester</groupId>
    <artifactId>TestTester</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>animal-sniffer-maven-plugin</artifactId>
                <version>1.13</version>
                <configuration>
                    <signature>
                        <groupId>TestAPI</groupId>
                        <artifactId>TestAPI</artifactId>
                        <version>0.0.1-SNAPSHOT</version>
                    </signature>
                </configuration>
                <executions>
                    <execution>
                        <id>default</id>
                        <phase>test</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>TestAPI</groupId>
            <artifactId>TestAPI</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

もちろん、このビルドも正常に実行されます。testMethodここで、を 2 つのパラメーターを持つように変更します。

public static void testMethod(String testString, String testString2)
{
    System.out.println(testString);
}

そして、2 番目のプロジェクトから使用します。

    MainInterface.testMethod("Hell", "o");

今回は、署名が変更されているため、2 番目のプロジェクトのビルドが失敗することが予想されます。signatures-file に保存されているものとは異なります。しかし、ビルドは成功し、animal-sniffer-plugin は次の 2 行のみを出力します。

[INFO] --- animal-sniffer-maven-plugin:1.13:check (default) @ TestTester ---
[INFO] Checking unresolved references to TestAPI:TestAPI:0.0.1-SNAPSHOT

mvn testたとえば、API で定義されていないものを呼び出しても、ビルドは成功します (呼び出します)。

MainInterface.undefinedMethod(1,2,3,4,5);

ユースケースが間違っているのでしょうか、それとも POM の構成ミスが原因でしょうか?

4

1 に答える 1

1

ヒントをくれた @ user944849 に感謝します。プラグインはその構成をデバッグ ログに出力しました。

[DEBUG] -----------------------------------------------------------------------
[DEBUG] Goal:          org.codehaus.mojo:animal-sniffer-maven-plugin:1.13:check (default-cli)
[DEBUG] Style:         Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <ignoreDependencies default-value="true"/>
  <localRepository>${localRepository}</localRepository>
  <outputDirectory>${project.build.outputDirectory}</outputDirectory>
  <project>${project}</project>
  <signature>
    <groupId>TestAPI</groupId>
    <artifactId>TestAPI</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </signature>
  <skip default-value="false">${animal.sniffer.skip}</skip>
</configuration>
[DEBUG] =======================================================================

設定があったため、依存関係が無視されていることが判明しました<ignoreDependencies default-value="true"/>。pom<ignoreDependencies>true</ignoreDependencies>にプラグイン構成を入れると、問題が解決しました。

また、コンパイル エラーを回避するために、変更した API プロジェクトをリポジトリに再インストールする必要がありました (署名のビルドをスキップしました)。

于 2015-02-25T08:27:03.823 に答える