Suppress violations¶
Special annotation could be used to suppress violations: examples
Default annotation¶
Add dependency on the annotation artifact:
implementation "org.codehaus.mojo:animal-sniffer-annotations:1.24"
Use provided
scope if you can.
Annotation is configured by default, so you can simply use annotation to suppress violation:
@IgnoreJRERequirement
private Optional param;
Custom annotation¶
You can define your own annotation:
package com.mycompany
@Retention(RetentionPolicy.CLASS)
@Documented
@Target({ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.TYPE})
public @interface SuppressSignatureCheck {}
Configure annotation:
animalsniffer {
annotation = 'com.mycompany.SuppressSignatureCheck'
}
Now check will skip blocks annotated with your annotation:
@SuppressSignatureCheck
private Optional param;
Ignore classes¶
Your project could target multiple Java versions and so reference classes, not present in a signature.
For example, your implementation could try to use Java 7 Paths
and if the class is not available, fall back
to the Java 6 implementation. In this case Paths
could be added to the ignored classes:
animalsniffer {
ignore 'java.nio.file.Paths'
}
Now usages of Paths
will not cause warnings.
Multiple ignored classes could be defined:
animalsniffer {
ignore 'java.nio.file.Paths', 'some.other.Class'
}
Or
animalsniffer {
ignore 'java.nio.file.Paths'
ignore 'some.other.Class'
}
Or by directly assigning collection:
animalsniffer {
ignore = ['java.nio.file.Paths', 'some.other.Class']
}
Entire packages could be ignored using asterisk:
animalsniffer {
ignore 'some.pkg.*'
}
See more info in the documentation.