by ZacSweers

A Kotlin compiler plugin that generates redacted toString() implementations.

140 Stars 8 Forks Last release: Not found Apache License 2.0 25 Commits 4 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:


A Kotlin compiler plugin that generates redacted


Inspired by the

extension for AutoValue.


Include the gradle plugin in your project, define a

annotation, and apply it to any properties that you wish to redact.
annotation class Redacted

data class User(val name: String, @Redacted val phoneNumber: String)

When you call

properties are hidden:
User(name=Bob, phoneNumber=██)

If your annotation is applied to the class, then

will emit a single replacement string:
annotation class Redacted

@Redacted data class SensitiveData(val ssn: String, val birthday: String)



Apply the gradle plugin.

buildscript {
  dependencies {
    classpath "dev.zacsweers.redacted:redacted-compiler-plugin-gradle:x.y.z"

apply plugin: 'dev.zacsweers.redacted.redacted-gradle-plugin'

And that's it! The default configuration will add the

artifact (which has a
annotation you can use) and wire it all automatically. Just annotate what you want to redact.

You can configure custom behavior with properties on the

redacted {
  // Define a custom annotation. The -annotations artifact won't be automatically added to
  // dependencies if you define your own!
  redactedAnnotation = "dev.zacsweers.redacted.annotations.Redacted" // Default

// Define whether or not this is enabled. Useful if you want to gate this behind a dynamic // build configuration. enabled = true // Default

// Define a custom replacement string for redactions. replacementString = "██" // Default }

Android Per-Variant Configuration

If using Android, you can optionally configure the plugin to be applied on a per-variant basis via

. This is similar to the Android Gradle Plugin's native
API, except with an
function to override the enabled status and there is no
property. If not overridden, the default is to match the
extension's value. Other
APIs should behave as expected (buildType, flavors, name, etc).

Note: Variants with different

values will have to be compiled separately. This is common in most multi-variant projects anyway, but something to be aware of.
redacted {
  enabled = true // Default
  androidVariantFilter {
    // Don't enable on debug
    if ( == "debug") {

Snapshots of the development version are available in Sonatype's



  • Kotlin compiler plugins are not a stable API! Compiled outputs from this plugin should be stable, but usage in newer versions of kotlinc are not guaranteed to be stable.
  • IDE support is not currently possible. See #8.


Copyright (C) 2018 Zac Sweers

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.