Error-prone in Gradle multi-module project

283 views Asked by At

How to enable error-prone for some modules in a multi-module Gradle project? I want to have the ability to turn on error-prone for several modules (not for all).

1

There are 1 answers

0
chehsunliu On

You can share this build logic as a plugin in buildSrc and only apply this plugin to your target modules.

For example, this sample in the official website https://docs.gradle.org/current/samples/sample_convention_plugins.html has two plugins and three modules:

├── buildSrc
│   ├── build.gradle
│   ├── settings.gradle
│   └── src
│       └── main
│           └── groovy
│               ├── myproject.java-conventions.gradle
│               └── myproject.library-conventions.gradle
├── internal-module
│   └── build.gradle
├── library-a
│   ├── build.gradle
│   └── README.md
├── library-b
│   ├── build.gradle
│   └── README.md
└── settings.gradle

Two of them apply the myproject.library-conventions and only one apply the myproject.java-conventions plugin:

// internal-module/build.gradle
plugins {
    id 'myproject.java-conventions'
}

dependencies {
    // internal module dependencies
}
// library-a/build.gradle
plugins {
    id 'myproject.library-conventions'
}

dependencies {
    implementation project(':internal-module')
}
// library-b/build.gradle
plugins {
    id 'myproject.library-conventions'
}

dependencies {
    implementation project(':internal-module')
}