Coder Social home page Coder Social logo

gradle-codeowners-plugin's Introduction

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"))

gradle-codeowners-plugin's People

Contributors

dependabot[bot] avatar gmazzo avatar gradle-update-robot avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.