The maven-animal-sniffer plugin promises to tell me if my co开发者_JAVA百科de has any references to Java 1.6 (or newer) APIs. This is important to those of us who develop on MacOSX Snow Leopard (which has only an official 1.6) but need to deliver to 1.5 environments.
Sadly, when trying to use it, I get all Java API calls reported as violations.
I'm not the only person to experience this problem, but apparently plenty of other people succeed.
If someone has a working POM snippet for this purpose, it would make a really helpful answer.
Note that I'm trying to use the version published on central (1.4) not the one (1.2) back on org.jvnet.
I've used the following configuration successfully for a project that had to run with a 1.4 JVM:
<project>
...
<properties>
<jdk.level>1.4</jdk.level>
</properties>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${jdk.level}</source>
<target>${jdk.level}</target>
</configuration>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jvnet</groupId>
<artifactId>animal-sniffer</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>compile</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<signature>
<groupId>org.jvnet.animal-sniffer</groupId>
<artifactId>java${jdk.level}</artifactId>
<version>1.0</version>
</signature>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.animal-sniffer</groupId>
<artifactId>java${jdk.level}</artifactId>
<version>1.0</version>
<type>sig</type>
</dependency>
</dependencies>
</plugin>
...
</plugins>
</build>
</project>
After fighting with different versions of animal-sniffer and collecting bits of information related to it from here and there, i finally managed to use it =)
For a list of available signatures and their maven coordinates see http://mojo.codehaus.org/signatures/ . There is no need to declare a dependency on a signature.
The following example gives the correct configuration for a manual (mvn clean compile animal-sniffer:check) check against Java 1.5:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java15</artifactId>
<version>1.0</version>
</signature>
</configuration>
</plugin>
The following example, in addition to making possible to check signatures manually, will also automatically run the animal-sniffer check goal during the verify phase:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java15</artifactId>
<version>1.0</version>
</signature>
</configuration>
<executions>
<execution>
<id>animal-sniffer</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
精彩评论