Coder Social home page Coder Social logo

ktargeter build Maven Central GitHub License

⚠ Maintainer Wanted

This project is not actively being maintained. If you want to take the lead in developing Ktargeter further, please leave a comment under this issue.

English | 한국어

ktargeter logo

Ktargeter is a Kotlin compiler plugin that allows overriding annotation use-site targets for properties. Using Java annotations in Kotlin code often requires specifying use-site targets, which is inconvenient and leads to bugs in runtime when a target is not specified. Instead of memorizing whether it is @get:Email, @field:Email, or @set:Email. You can configure it once in Gradle and use @Email throughout your code. Ktargeter works during compilation and adds no overhead in runtime.

As an example, you can replace this code:

data class User(
    @get:One
    val firstName: String,
    @field:Two
    val lastName: String,
    @set:Three
    var birthday: LocalDate,     
)

with this:

data class User(
    @One
    val firstName: String,
    @Two
    val lastName: String,
    @Three
    var birthday: LocalDate,     
)

Usage

Supported Kotlin versions: 1.4, 1.5, and 1.6.

Add ktargeter to the plugins section of your build.gradle:

plugins {
    id 'org.ktargeter' version '0.3.0'
}

Define annotations with new targets in the following way:

ktargeter.annotations = [
        "com.sample.annotations.One"  : "get",
        "com.sample.annotations.Two"  : "field",
        "com.sample.annotations.Three": "set"
]

This will instruct the plugin to override use-site targets for the specified annotations when they are used on properties.

Ktargeter will not override targets of annotations that specify their targets explicitly.

Compatibility

Pick a plugin version depending on the Kotlin version used in your project.

Kotlin version Ktargeter version
Kotlin 1.6 or newer Ktargeter 0.3.0
Kotlin 1.5 Ktargeter 0.2.1
Kotlin 1.4 Ktargeter 0.1.0

Contributing

If you found a bug or have an idea on how to improve ktargeter feel free to open an issue. You can also propose your changes via a Pull Request.

Development setup

In order to debug/develop ktargeter, use the following steps:

  1. Install Gradle and Kotlin plugins into the local Maven repository:
./gradlew publishToMavenLocal -x signMavenPublication \
 -x signPluginMavenPublication -x signSimplePluginPluginMarkerMavenPublication
  1. Import the project to IntelliJ IDEA (the Debug Kotlin Plugin configuration should be available in Run/Debug configuration box).

  2. Add breakpoints to the classes in the compiler-plugin module.

  3. Clone the sample project and build it using the following command:

./gradlew clean build --no-daemon -Dorg.gradle.debug=true \
 -Dkotlin.compiler.execution.strategy="in-process" \
 -Dkotlin.daemon.jvm.options="-Xdebug,-Xrunjdwp:transport=dt_socket,address=5005,server=y,suspend=n"
  1. Run the Debug Kotlin Plugin configuration in Debug mode.

ktargeter's Projects

ktargeter doesn’t have any public repositories yet.

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.