Skip to content

premex-ab/ownership-gradle-plugin

Repository files navigation

Gradle code ownership verification plugin

A gradle plugin that will verify ownership files are in place in projects and have required information.

Use it
plugins {
    id("se.premex.ownership") version "LATEST_VERSION"
}
Configure it
ownership {
    validateOwnership = true
    generateGithubOwners = true
    generateBitbucketOwners = true
}
Validate and generate ownership files (combined):
./gradlew ownership

This combined task validates OWNERSHIP.toml files and generates VCS CODEOWNERS files (both validation and generation in a single command).

Verify ownership files is in place:
./gradlew validateOwnership

Outputs from validation is available in build/reports/ownershipValidation/

Generate GitHub and Bitbucket CODEOWNERS files:
./gradlew generateOwnership

This task generates CODEOWNERS files for GitHub and/or Bitbucket based on your OWNERSHIP.toml files:

  • When generateGithubOwners = true: Creates .github/CODEOWNERS
  • When generateBitbucketOwners = true: Creates .bitbucket/CODEOWNERS

The generated files map directory paths to owners defined in your OWNERSHIP.toml files.

validateOwnership will be run as part of check tasks
./gradlew check

OWNERSHIP.toml file format

Basic example

version = 1

[owner]
user = "@team-name"

The user field supports:

  • GitHub teams: @org/team-name or @team-name
  • GitHub usernames: @username
  • Email addresses: [email protected]

Advanced example with custom path configurations

version = 1

[owner]
user = "@platform-team"

[custom]
owners = [
    ["*.js", "@frontend-team"],
    ["*.ts", "@frontend-team"],
    ["*.java", "@backend-team"],
    ["*.kt", "@backend-team"],
    ["docs/*", "[email protected]"]
]

The [custom] section allows you to specify different owners for specific file patterns or paths within the directory containing the OWNERSHIP.toml file.

Multi-module projects

You can place OWNERSHIP.toml files in multiple directories:

root/
├── OWNERSHIP.toml          # Root ownership (applies to * path)
├── frontend/
│   └── OWNERSHIP.toml      # Applies to frontend/ path
└── backend/
    └── OWNERSHIP.toml      # Applies to backend/ path

The generated CODEOWNERS file will combine all ownership rules from all OWNERSHIP.toml files found in your project.

Example generated CODEOWNERS file

Given the following project structure:

root/
├── OWNERSHIP.toml (user = "@platform-team", custom: *.js → @frontend-team)
├── backend/
│   └── OWNERSHIP.toml (user = "@backend-team")

The generated .github/CODEOWNERS file would look like:

# This file is automatically generated by Premex ownership plugin
# Do not edit manually.
# https://plugins.gradle.org/plugin/se.premex.ownership
# https://github.com/premex-ab/ownership-gradle-plugin

# OWNERSHIP.toml
*	@platform-team
# Custom configurations
*.js	@frontend-team
# backend/OWNERSHIP.toml
backend/	@backend-team

Coming Soon!

Here are some ideas that we are thinking about. We are also not limited to these and would love to learn more about your use cases.

  • Support for verifying codeownership files is in place
  • Better rules for validating content in ownership files
  • Support for having codeownership files anywhere in the code and not only in a projects root
  • Generate GitHub & Bitbucket codeownership files based on the toml files
  • Generate html reports of code ownerships and code health

About

Gradle ownership plugin

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages