Trackable Compiler Plugin (Gradle)

A Kotlin compiler plugin that generates trackable implementations.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.github.hadilq.trackable
ArtifactId

ArtifactId

trackable-compiler-plugin-gradle
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

Trackable Compiler Plugin (Gradle)
A Kotlin compiler plugin that generates trackable implementations.
Project URL

Project URL

https://github.com/hadilq/trackable-compiler-plugin/
Source Code Management

Source Code Management

https://github.com/hadilq/trackable-compiler-plugin/

Download trackable-compiler-plugin-gradle

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.hadilq.trackable/trackable-compiler-plugin-gradle/ -->
<dependency>
    <groupId>com.github.hadilq.trackable</groupId>
    <artifactId>trackable-compiler-plugin-gradle</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.hadilq.trackable/trackable-compiler-plugin-gradle/
implementation 'com.github.hadilq.trackable:trackable-compiler-plugin-gradle:0.1.1'
// https://jarcasting.com/artifacts/com.github.hadilq.trackable/trackable-compiler-plugin-gradle/
implementation ("com.github.hadilq.trackable:trackable-compiler-plugin-gradle:0.1.1")
'com.github.hadilq.trackable:trackable-compiler-plugin-gradle:jar:0.1.1'
<dependency org="com.github.hadilq.trackable" name="trackable-compiler-plugin-gradle" rev="0.1.1">
  <artifact name="trackable-compiler-plugin-gradle" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.hadilq.trackable', module='trackable-compiler-plugin-gradle', version='0.1.1')
)
libraryDependencies += "com.github.hadilq.trackable" % "trackable-compiler-plugin-gradle" % "0.1.1"
[com.github.hadilq.trackable/trackable-compiler-plugin-gradle "0.1.1"]

Dependencies

runtime (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.3.71
org.jetbrains.kotlin : kotlin-gradle-plugin-api jar 1.3.71

Project Modules

There are no modules declared in this project.

Maven Central

trackable-compiler-plugin

A Kotlin compiler plugin that generates trackable method fun track() : String implementations for classes that annotated by @Trackable. This method would return the class name String. Also for classes that their parent annotated with @Trackable, this method would be generated with current class name. However, if you want to override the return String you can use @Trackable(trackWith = "Something else!") to change the return value. It's useful when your classes are obfuscated in the product and you need their names to log an event.

NOTICE it would not resolve the generated method in the IDE, but will resolve it on build-time.

Usage

Include the gradle plugin in your project, apply @Trackable annotation to any classes that you wish to track or on their parent class or interfaces.

@Retention(BINARY)
@Target(CLASS)
annotation class Trackable(val trackWith: String = "")

@Trackable
class TrackableClass

When you call TrackableClass().track() you must receive the name of the class, which is TrackableClass, Or if you want to change that string use trackWith params as below.

@Retention(BINARY)
@Target(CLASS)
annotation class Trackable(val trackWith: String = "")

@Trackable(trackWith = "Something else!")
class TrackableClass

So the track method would return Something else!.

Installation

Not published yet but it should be by applying the gradle plugin as follows in the future.

buildscript {
  dependencies {
    classpath "com.github.hadilq.trackable:trackable-compiler-plugin-gradle:x.y.z"
  }  
}

apply plugin: 'com.github.hadilq.trackable.trackable-gradle-plugin'

And that's it! The default configuration will add the -annotations artifact (which has a @Trackable annotation you can use) and wire it all automatically. Just annotate what you want to your trackable class.

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

You can configure custom behavior with properties on the trackable extension.

trackable {
  // Define a custom annotation. The -annotations artifact won't be automatically added to
  // dependencies if you define your own!
  trackableAnnotation = "com.github.hadilq.trackable.annotations.Trackable" // Default

  // In case of a custom annotation above you can change the name of `trackWith` param by this variable.
  trackWith = "trackWith" // Default

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

  // Define the name of generated method.
  getterName = "track" // Default
}

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.

Contribution

Just create your branch from the master branch, change it, write additional tests, satisfy all tests, create your pull request, thank you, you're awesome.

Versions

Version
0.1.1
0.1.0