has anyone got the animal sniffer plugin to work?

∥☆過路亽.° 提交于 2019-12-24 01:40:05

问题


The maven-animal-sniffer plugin promises to tell me if my code 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.


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/2173302/has-anyone-got-the-animal-sniffer-plugin-to-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!