在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):xvik/gradle-animalsniffer-plugin开源软件地址(OpenSource Url):https://github.com/xvik/gradle-animalsniffer-plugin开源编程语言(OpenSource Language):Groovy 96.9%开源软件介绍(OpenSource Introduction):gradle-animalsniffer-pluginAboutGradle AnimalSniffer plugin for Java or Groovy projects. AnimalSniffer is used to check compatibility with lower Java versions (when compiling with a newer Java version) or Android (SDK version). It is implemented the same way as core Gradle quality plugins (Checkstyle, PMD etc):
A task is registered for each source set (animalsnifferMain, animalsnifferTest) and attached to the Advanced features:
ApplicabilityIf you're using JDK 9 or above then you can use the --release flag instead of the plugin: compileJava {
options.compilerArgs.addAll(['--release', '7'])
} Direct The plugin could still be useful:
Summary
Setupbuildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.5.4'
}
}
apply plugin: 'ru.vyarus.animalsniffer' OR plugins {
id 'ru.vyarus.animalsniffer' version '1.5.4'
} CompatibilityIMPORTANT: The plugin only works when the The plugin is compiled for Java 8, and is compatible with Java 11.
UsageAdditional tasks will be assigned to the $ gradlew check SignaturesAnimalSniffer requires a signature file to check against. To define a signature (or multiple signatures) use
the To check Java version compatibility: repositories { mavenCentral() }
dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
} To check Android compatibility: repositories { mavenCentral() }
dependencies {
signature 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature'
} To check both Java version and Android compatibility: dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
signature 'net.sf.androidscents.signature:android-api-level-14:4.0_r4@signature'
} In the last case animalsniffer will run 2 times for each signature. You may see the same errors two times if a class/method is absent in both signatures. Each error message in the log (and file) will also contain the signature name to avoid confusion. When no signatures are defined animalsniffer tasks will always pass. You can also use custom libraries signatures to check version compatibility. ScopeAll project dependencies are excluded from the analysis: only classes from your source set are checked. By default, all source sets are checked. To only check main sources: animalsniffer {
sourceSets = [sourceSets.main]
} OutputViolations are always printed to the console. Example output:
NOTE: text report file will contain simplified report (error per line):
NOTE: when multiple signatures are used, output will contain the signature name in the error message to avoid confusion. Suppress violationsAn annotation could be used to suppress violations: examples Default annotationAdd dependency on the annotation artifact: implementation "org.codehaus.mojo:animal-sniffer-annotations:1.16" Use @IgnoreJRERequirement
private Optional param; Custom annotationYou 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; Extend signatureYour 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 animalsniffer {
ignore 'java.nio.file.Paths'
} Now usages of 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. ConfigurationConfiguration example: animalsniffer {
toolVersion = '1.20'
sourceSets = [sourceSets.main]
ignoreFailures = true
reportsDir = file("$project.buildDir/animalsnifferReports")
annotation = 'com.mypackage.MyAnnotation'
ignore = ['java.nio.file.Paths']
} There are no required configurations - the plugin will generate defaults for all of them.
NOTE: TasksThe animalsniffer task is registered for each source set:
The Tasks support text report, enabled by default. To disable reports for a task: animalsnifferMain.reports.text.enabled = false or for all tasks: tasks.withType(AnimalSniffer) {
reports.text.enabled = false
} Animalsniffer task is a SourceTask and may be configured to include/exclude classes from check. NOTE: The task operates on compiled classes and not sources! Be careful when defining patterns. For example, to exclude classes in a 'invalid' subpackage from check: animalsnifferMain {
exclude('**/invalid/*')
} Advanced featuresRead wiki for advanced features:
Might also like
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论