该插件允许运行 Apache RAT 发布审计工具,专注于许可证。
在你的 build.gradle(.kts) 文件中:
plugins {
id("org.nosphere.apache.rat") version "0.8.1"
}
该插件注册了一个名为 rat 的任务,你可以在 build.gradle(.kts) 文件中配置它:
tasks.rat {
// Use the default RAT license header matchers, defaults to `true`
addDefaultMatchers.set(false)
// Add custom substring license header matchers
substringMatcher("family", "category", "pattern-1", "pattern-2")
// Declare approved license families, if used, any non-declared family won't be approved
approvedLicense("MIT")
// Input directory, defaults to '.'
inputDir.set("some/path")
// List of Gradle exclude directives, defaults to ['**/.gradle/**']
excludes.add("**/build/**")
// RatTask 0.5.0+ implements PatternFilterable
exclude { it.file in configurations.someConf.files }
// Rat excludes file, one directive per line
excludeFile.set(layout.projectDirectory.file(".rat-excludes.txt"))
// XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
reportDir.set(file("some/other/path"))
// Custom XSL stylesheet for the HTML report
stylesheet.set(file("custom/rat-html-stylesheet.xsl"))
// Fail the build on rat errors, defaults to true
failOnError.set(false)
}
rat {
// Input directory, defaults to '.'
inputDir.set(file("some/path"))
// List of Gradle exclude directives, defaults to ['**/.gradle/**']
excludes.add("**/build/**")
// Rat excludes file, one directive per line
excludeFile.set(layout.projectDirectory.file(".rat-excludes.txt"))
// XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
reportDir.set(file("some/other/path"))
// Custom XSL stylesheet for the HTML report
stylesheet.set(file("custom/rat-html-stylesheet.xsl"))
// Fail the build on rat errors, defaults to true
failOnError.set(false)
// Prints the list of files with unapproved licences to the console, defaults to false
verbose.set(true)
}
你可以通过调用 Gradle 来运行 rat 任务:
gradle rat
如果项目有 check 任务,那么 rat 任务会自动注册为依赖该任务。
当 Rat 审计失败时,会打印出 HTML 报告的可点击 URL:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':rat'.
> Apache Rat audit failure - 35 unapproved licenses
See file:///path/to/build/reports/rat/index.html

| 插件 | 最低 Java | 最低 Gradle | 最高 Gradle | 配置缓存 | 构建缓存 |
|---|
0.8.1 | 1.8 | 6.0 | 8.x | 🟢 | 🟢 |
0.8.0 | 1.8 | 6.0 | 8.x | 🟡 | 🟢 |
0.7.1 | 1.8 | 6.0 | 7.x | 🟡 | 🟢 |
0.7.0 | 1.8 | 6.0 | 7.x | 🟡 | 🟢 |
0.6.0 | 1.6 | 4.7 | 6.x | 🟡 | 🟢 |
0.5.3 | 1.6 | 4.7 | 6.x | 🔴 | 🟢 |
0.5.2 | 1.6 | 4.7 | 6.x | 🔴 | 🟢 |
0.5.1 | 1.6 | 4.7 | 5.x | 🔴 | 🟢 |
0.5.0 | 1.6 | 4.7 | 5.x | 🔴 | 🟢 |
0.4.0 | 1.6 | 4.7 | 5.x | 🔴 | 🟢 |
0.3.1 | 1.6 | 2.14 | 4.x | 🔴 | 🟢 |
0.3.0 | 1.6 | 2.14 | 4.x | 🔴 | 🟢 |
0.2.0 | 1.6 | 2.14 | 4.x | 🔴 | 🟢 |
0.1.0 | 1.6 | 2.14 | 4.x | 🔴 | 🟢 |