A Gradle plugin to propagate CODEOWNERS information to classes
It consists on 3 different plugins, each one providing a different set of features and targeting different use cases:
- The
io.github.gmazzo.codeowners
plugin adds a Gradle report of classes' ownership - The
io.github.gmazzo.codeowners.jvm
plugin propagates the classes' ownership information to runtime. It supports any JVM build (java
,groovy
, etc) that produces.class
files, but JVM-only - The
io.github.gmazzo.codeowners.kotlin
Kotlin Compiler plugin propagates the classes' ownership information to runtime. It supports any Kotlin build (jvm
,android
,multiplatform
, etc, but Kotlin-only)
This plugin is designed to work as a whole build plugin, but you can selectively apply it to target the modules where you actually care about CODEOWNERS propagation.
The simplest setup is to apply the plugin at the root project, and then to each submodule. At root build.gradle.kts
add:
plugins {
id("io.github.gmazzo.codeowners") version "<latest>"
}
subprojects {
apply(plugin = "io.github.gmazzo.codeowners")
}
You should apply the right plugins according to your needs:
io.github.gmazzo.codeowners
(Report) is for the generating codeowners-like file by Java/Kotlin classes namesio.github.gmazzo.codeowners.jvm
(JVM) is for propagating codeowners info to JVM-only projectsio.github.gmazzo.codeowners.kotlin
(Kotlin) (recommended) is for propagating codeowners info to for pure Kotlin projects (including JVM and multiplatform)
Plugin / Feature | Report | JVM | Kotlin |
---|---|---|---|
Generates class-like reports at build time | ✅ | ✅ * | ✅ * |
Propagates codeowners info to runtime | ❌ | ✅ | ✅ |
Works with JVM projects | ✅ | ✅ | ✅ |
Works with Multiplatform projects | ❌ | ❌ | ✅ |
Acurrancy: Codeowners info matches always the original file ones |
🟢 | 🟡 ** | 🟢 |
(*) inherited from io.github.gmazzo.codeowners
(Report) plugin
(**) because how the Java Resources API on JVM the ownership information may be inaccurate in some cases. See Caveats on the approach for more details.
Later, you can query a class's owner by:
val ownersOfFoo = codeOwnersOf<Foo>()
or in Java:
Set<String> ownersOfFoo = CodeOwners.getCodeOwners(Foo.class);
Expection
s can also be attributed by inspecting its stacktrace (first match wins)
try {
// do some work
} catch (ex: Throwable) {
val ownersOfErr = ex.codeOwners
// report to its owner
}
or in Java:
try {
// do some work
} catch (Throwable ex) {
Set<String> ownersOfErr = CodeOwners.getCodeOwners(ex);
// report to its owner
}
At root's build.gradle.kts
add:
plugins {
id("io.github.gmazzo.codeowners") version "<latest>"
}
subprojects {
apply(plugin = "io.github.gmazzo.codeowners")
}
You must apply the plugin on every project that has source files. Those classes won't be computed otherwise. Applying it at the root project only, will only make sense on single module builds.
The expected format is the same as GitHub's and it can be located at any of the following paths:
$rootDir/CODEOWNERS
$rootDir/.github/CODEOWNERS
$rootDir/.gitlab/CODEOWNERS
$rootDir/docs/CODEOWNERS
codeOwners.codeOwnersFile.set(layout.projectDirectory.file("somePath/.CODEOWNERS"))