GithubHelp home page GithubHelp logo

izhangzhihao / unmeta Goto Github PK

View Code? Open in Web Editor NEW
32.0 4.0 2.0 141 KB

remove all Kotlin Metadata and DebugMetadata annotations from .class files

Home Page: https://plugins.gradle.org/plugin/io.github.izhangzhihao.unmeta

License: MIT License

Kotlin 100.00%
kotlin gradle-plugin obfuscation proguard kotlin-plugin r8 gradle metadata

unmeta's Introduction

Unmeta Kotlin gradle plugin ๐Ÿ˜

A Gradle plugin to remove all Kotlin @Metadata / @DebugMetadata / @SourceDebugExtension annotations from the compile output and jars.

Kotlin @Metadata and @DebugMetadata annotations are not fully processed by ProGuard / R8 and contain un-obfuscated symbol information, both in binary and plain text forms. This information can be used to more easily reverse engineer your code.

This plugin allows removing all Kotlin @Metadata / @DebugMetadata / @SourceDebugExtension annotations from generated class files. This is safe to do as long as:

  • you do not intend to use the resulting binaries as a Kotlin library (@Metadata annotations are used to determine Kotlin function definitions),
  • you are not using Kotlin Reflection (certain reflection functionality depends on the presence of the @Metadata annotations).

By using the Kotlin dsl in build.gradle.kt

plugins {
    kotlin("jvm")
    id("io.github.izhangzhihao.unmeta") version "1.0.2"
}

unmeta {
    enable.set(true)
}

To enable the plugin only for release builds add this section:

gradle.taskGraph.whenReady {
    if (allTasks.any { it.name.contains("release") }) {
        unmeta {
            enable.set(true)
        }
    } else {
        unmeta {
            enable.set(false)
        }
    }
}

By using the Groovy dsl in build.gradle

plugins {
    id 'org.jetbrains.kotlin.jvm' version '1.8.21'
    id "io.github.izhangzhihao.unmeta" version "1.0.2"
}

unmeta {
    enable.set(true)
}

To enable the plugin only for release builds add this section:

gradle.taskGraph.whenReady { graph ->
    if (graph.getAllTasks().any { it.name.contains("release") }) {
        unmeta {
            enable.set(true)
        }
    } else {
        unmeta {
            enable.set(false)
        }
    }
}

Verify

./gradlew clean jar --dry-run
:clean SKIPPED
:compileKotlin SKIPPED
:unmeta SKIPPED
:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:jar SKIPPED

You might need this to force the unmeta task runs before the jar task:

jar {
    mustRunAfter("unmeta")
}

Dependency substitution

Please note that the project relies on module name/group in order for dependency substitution to work properly. If you change only the plugin ID everything will work as expected. If you change module name/group, things might break and you probably have to specify a substitution rule.

Contributing ๐Ÿค

Feel free to open a issue or submit a pull request for any bugs/improvements.

./gradlew --project-dir plugin-build publishToMavenLocal

License ๐Ÿ“„

This template is licensed under the MIT License - see the License file for details.

unmeta's People

Contributors

izhangzhihao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

unmeta's Issues

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.