I want to use the animal sniffer to check a class against my own API, which contains just one class and one method:
package sniffertestapi;
public class MainInterface
{
public static void testMethod(String testString)
{
System.out.println(testString);
}
}
The following simple POM is used to build the project:
<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>
The build runs fine, it installs TestAPI-0.0.1-SNAPSHOT.signature and jar into my maven repository.
Next I want to add TestAPI as a dependency and use the testMethod
from another project.
package sniffertest;
import sniffertestapi.MainInterface;
public class Tester
{
public Tester()
{
MainInterface.testMethod("Hi");
}
}
In this project I added the animal sniffer plugin with another goal:
<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>
This build runs of course with success also. Now I change the testMethod
to have two parameters:
public static void testMethod(String testString, String testString2)
{
System.out.println(testString);
}
And use it from the second project:
MainInterface.testMethod("Hell", "o");
This time I expect the build for the second project to fail, because signature have changed. It differs from that one saved in signatures-file. But the build results in success and animal-sniffer-plugin outputs only these two lines:
[INFO] --- animal-sniffer-maven-plugin:1.13:check (default) @ TestTester ---
[INFO] Checking unresolved references to TestAPI:TestAPI:0.0.1-SNAPSHOT
Even if I call something not defined in my API the the build is successful (invoking mvn test
), for an instance:
MainInterface.undefinedMethod(1,2,3,4,5);
Do I have the wrong use-case or is it because of misconfiguration of the POM?
Thanks @user944849 for the hint. The plugin printed its configuration to the debug log:
[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] =======================================================================
It turned out the dependencies were ignored since there were a setting <ignoreDependencies default-value="true"/>
. Putting <ignoreDependencies>true</ignoreDependencies>
into the plugin configuration in the pom resolved my issue.
I had also to reinstall the modified API-project into repository (skipping the build of the signatures) to avoid compilation errors.