Skip to content

A set of Gradle plugins to propagate CODEOWNERS of classes to runtime for JVM and Kotlin Multiplatform

License

Notifications You must be signed in to change notification settings

gmazzo/gradle-codeowners-plugin

Repository files navigation

GitHub Maven Central Gradle Plugin Portal Build Status Coverage Users

gradle-codeowners-plugin

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:

  1. The io.github.gmazzo.codeowners plugin adds a Gradle report of classes' ownership
  2. 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
  3. 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)

Usage

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 names
  • io.github.gmazzo.codeowners.jvm (JVM) is for propagating codeowners info to JVM-only projects
  • io.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.

Getting ownership information at runtime

Later, you can query a class's owner by:

val ownersOfFoo = codeOwnersOf<Foo>()

or in Java:

Set<String> ownersOfFoo = CodeOwners.getCodeOwners(Foo.class);

Crash attribution

Expections 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
}

Recommended setup on multi module projects

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 CODEOWNERS file

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

Specifying CODEOWNERS file location

codeOwners.codeOwnersFile.set(layout.projectDirectory.file("somePath/.CODEOWNERS"))

About

A set of Gradle plugins to propagate CODEOWNERS of classes to runtime for JVM and Kotlin Multiplatform

Resources

License

Stars

Watchers

Forks

Packages

No packages published