Apache RAT (Release Audit Tool) Gradle Plugin

September 11, 2026 ยท View on GitHub

CI Apache License 2

This plugin allows to run the Apache RAT release audit tool, focused on licenses.

It bundles Apache RAT 0.18. The RAT version is an implementation detail and cannot be changed. RAT 0.18 needs Java 17; Gradle itself may run on Java 8, see Java for RAT.

Installation

In your build.gradle(.kts) file:

plugins {
    id("org.nosphere.apache.rat") version "0.11.0"
}

Upgrading from 0.9.0? See the migration guide.

Usage

The plugin registers a task named rat that you can configure in your build.gradle(.kts) file:

Kotlin DSL
tasks.rat {

    // Use the default RAT license header matchers, defaults to `true`
    addDefaultMatchers.set(false)

    // Add custom substring license header matchers
    // First argument is the license family category: at most 5 characters,
    // and it must not clash with another license family
    substringMatcher("MYFOO", "My Foo License", "pattern-1", "pattern-2")

    // Declare approved license families, by name or by category
    // If used, any non-declared family won't be approved
    approvedLicense("MIT")

    // Input directory, defaults to '.'
    inputDir.set(file("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 }

    // XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
    reportDir.set(file("some/other/path"))

    // Fail the build when the audit finds unapproved licenses, defaults to true
    // Invalid configuration always fails the build, whatever this is set to
    failOnError.set(false)

    // Print the unapproved files and the license families in use, defaults to false
    verbose.set(true)
}
Groovy DSL
rat {

    // Use the default RAT license header matchers, defaults to `true`
    addDefaultMatchers.set(false)

    // Add custom substring license header matchers
    // First argument is the license family category: at most 5 characters,
    // and it must not clash with another license family
    substringMatcher("MYFOO", "My Foo License", "pattern-1", "pattern-2")

    // Declare approved license families, by name or by category
    // If used, any non-declared family won't be approved
    approvedLicense("MIT")

    // Input directory, defaults to '.'
    inputDir.set(file("some/path"))

    // List of Gradle exclude directives, defaults to ['**/.gradle/**']
    excludes.add("**/build/**")

    // XML, TXT and HTML reports directory, defaults to 'build/reports/rat'
    reportDir.set(file("some/other/path"))

    // Fail the build when the audit finds unapproved licenses, defaults to true
    // Invalid configuration always fails the build, whatever this is set to
    failOnError.set(false)

    // Print the unapproved files and the license families in use, defaults to false
    verbose.set(true)
}

Excluding files

The task implements Gradle's PatternFilterable. Use exclude(...) to keep files out of the audit:

tasks.rat {
    exclude("**/*.txt")                        // Ant-style pattern
    exclude("build/**")                        // whole directory
    exclude { it.name.startsWith("generated") } // arbitrary rule
}

License families

RAT 0.18 knows these license families. Use either the name or the category in approvedLicenses:

CategoryName
ALApache License
BSD-3BSD 3 clause
CDDL1COMMON DEVELOPMENT AND DISTRIBUTION LICENSE Version 1.0
GPLGNU General Public License family
MITThe MIT License
OASISOASIS Open License
W3CW3C Software Copyright
W3CDW3C Document Copyright

A value that matches no family fails the build and lists the valid ones.

Reports

The task writes three files to reportDir:

FileContent
index.htmlHuman readable report
rat-report.txtRAT's plain text report
rat-report.xmlRAT's XML report, see RAT's rat-report.xsd

Running

gradle rat

If the project has a check task, it is automatically made dependent on the rat task.

When a Rat audit fails, a clickable URL of the HTML report will be printed out:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':rat'.
> A failure occurred while executing org.nosphere.apache.rat.RatWork
   > Apache Rat audit failure - 35 unapproved licenses
     	See file:///path/to/build/reports/rat/index.html

Apache Rat HTML Report

Java for RAT

RAT 0.18 needs Java 17. You normally have nothing to configure: the plugin runs RAT in a separate worker process and picks its JVM by itself:

  • Gradle running on Java 17 or later: the worker uses the same JVM as Gradle.

  • Gradle running on Java 8 to 16: the plugin asks Gradle's toolchain support for a Java 17 and runs the worker on it. Any JDK 17 Gradle can detect works, see the toolchain documentation. Without one, the build fails with Gradle's own message. On recent Gradle versions it reads:

    Cannot find a Java installation on your machine ... matching: {languageVersion=17, ...}.
    Toolchain download repositories have not been configured.
    

    Install a JDK 17, or let Gradle download one by declaring a toolchain repository in settings.gradle(.kts). For example, you can use the Foojay Toolchains Plugin.

To pick the JVM yourself, set the javaLauncher task property to a Java 17 or later. The javaToolchains extension needs the java-base plugin, or the lighter jvm-toolchains plugin on Gradle 7.6 and later:

plugins {
    id("jvm-toolchains")
}
tasks.rat {
    javaLauncher.set(javaToolchains.launcherFor {
        languageVersion.set(JavaLanguageVersion.of(21))
    })
}

verbose.set(true) prints which JVM the worker runs on.

Logging

The task is quiet on a successful audit. To see RAT's own output, use Gradle's log levels:

CommandOutput
gradle ratnothing from RAT
gradle rat --infoRAT's progress messages
gradle rat --debugRAT's full trace, one line per audited file

Set verbose.set(true) to always print the list of unapproved files and the license families in use.

Compatibility matrix

PluginMin JavaMin GradleMax GradleConfiguration Cache (1)Isolated Projects (2)Build Cache (3)
0.11.01.8 (Gradle), 17 (RAT)7.09.x๐ŸŸข๐ŸŸข๐ŸŸข
0.10.01.86.09.x๐ŸŸข๐ŸŸข๐ŸŸข
0.9.01.86.09.x๐ŸŸข๐ŸŸข๐ŸŸข
0.8.21.86.09.x๐ŸŸข๐ŸŸข๐ŸŸข
0.8.11.86.08.x๐ŸŸข๐ŸŸข๐ŸŸข
0.8.01.86.08.x๐ŸŸก๐ŸŸก๐ŸŸข
0.7.11.86.07.x๐ŸŸก๐ŸŸก๐ŸŸข
0.7.01.86.07.x๐ŸŸก๐ŸŸก๐ŸŸข
0.6.01.64.76.x๐ŸŸก๐Ÿ”ด๐ŸŸข
0.5.31.64.76.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.5.21.64.76.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.5.11.64.75.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.5.01.64.75.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.4.01.64.75.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.3.11.62.144.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.3.01.62.144.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.2.01.62.144.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข
0.1.01.62.144.x๐Ÿ”ด๐Ÿ”ด๐ŸŸข