Redacted Compiler Plugin (Gradle)

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

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

dev.zacsweers.redacted.redacted-gradle-plugin
ArtifactId

ArtifactId

dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin
Last Version

Last Version

0.7.0
Release Date

Release Date

Type

Type

pom
Description

Description

Redacted Compiler Plugin (Gradle)
A Kotlin compiler plugin that generates redacted toString() implementations.
Project URL

Project URL

https://github.com/ZacSweers/redacted-compiler-plugin/
Source Code Management

Source Code Management

https://github.com/ZacSweers/redacted-compiler-plugin/

Download dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin

How to add to project

<!-- https://jarcasting.com/artifacts/dev.zacsweers.redacted.redacted-gradle-plugin/dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin/ -->
<dependency>
    <groupId>dev.zacsweers.redacted.redacted-gradle-plugin</groupId>
    <artifactId>dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin</artifactId>
    <version>0.7.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/dev.zacsweers.redacted.redacted-gradle-plugin/dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin/
implementation 'dev.zacsweers.redacted.redacted-gradle-plugin:dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin:0.7.0'
// https://jarcasting.com/artifacts/dev.zacsweers.redacted.redacted-gradle-plugin/dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin/
implementation ("dev.zacsweers.redacted.redacted-gradle-plugin:dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin:0.7.0")
'dev.zacsweers.redacted.redacted-gradle-plugin:dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin:pom:0.7.0'
<dependency org="dev.zacsweers.redacted.redacted-gradle-plugin" name="dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin" rev="0.7.0">
  <artifact name="dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin" type="pom" />
</dependency>
@Grapes(
@Grab(group='dev.zacsweers.redacted.redacted-gradle-plugin', module='dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin', version='0.7.0')
)
libraryDependencies += "dev.zacsweers.redacted.redacted-gradle-plugin" % "dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin" % "0.7.0"
[dev.zacsweers.redacted.redacted-gradle-plugin/dev.zacsweers.redacted.redacted-gradle-plugin.gradle.plugin "0.7.0"]

Dependencies

compile (1)

Group / Artifact Type Version
dev.zacsweers.redacted » redacted-compiler-gradle-plugin jar 0.7.0

Project Modules

There are no modules declared in this project.

redacted-compiler-plugin

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

Inspired by the auto-value-redacted extension for AutoValue.

Usage

Include the gradle plugin in your project, define a @Redacted annotation, and apply it to any properties that you wish to redact.

@Retention(SOURCE)
@Target(PROPERTY)
annotation class Redacted

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

When you call toString() any @Redacted properties are hidden:

User(name=Bob, phoneNumber=██)

If your annotation is applied to the class, then toString() will emit a single replacement string:

@Retention(SOURCE)
@Target(CLASS)
annotation class Redacted

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

Installation

Apply the gradle plugin.

plugins {
  id("dev.zacsweers.redacted") version <version>
}

And that's it! The default configuration will add the -annotations artifact (which has a @Redacted 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 extension.

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
}

Snapshots of the development version are available in Sonatype's snapshots repository.

Caveats

  • 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.

License

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

   http://www.apache.org/licenses/LICENSE-2.0

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.

Versions

Version
0.7.0
0.6.1
0.6.0
0.5.0
0.4.0
0.3.0
0.2.0-1.4-M3