Skip to content

gmazzo/gradle-import-classes-plugin

Repository files navigation

GitHub Maven Central Gradle Plugin Portal Build Status Coverage Users

Contributors

gradle-import-classes-plugin

A Gradle plugin to import and repackage dependencies Proguard tool.

Usage

Apply the plugin:

plugins {
    java
    id("io.github.gmazzo.importclasses") version "<latest>"
}

importClasses {
    dependencies("org.apache.commons:commons-lang3:3.14.0")
    repackageTo = "org.test.imported"
    keep("org.apache.commons.lang3.StringUtils")
}

You can also use importClasses and importClassesLibrary configurations in the project's dependencies block:.

dependencies {
    importClasses("org.apache.commons:commons-lang3:3.14.0")
}

The companion importClassesLibrary will be mapped to Proguard's -libraryjars option.

Then the SourceSet will have the class org.apache.commons.lang3.StringUtils from ( org.apache.commons:commons-lang3:3.14.0) imported and repackaged as org.test.imported.StringUtils.

package org.test;

import org.test.imported.StringUtils;

public class Foo {

    public String swapCase(String string) {
        return StringUtils.swapCase(string);
    }

}

Note

This plugin uses Gradle's Artifact Transform by running Proguard on the target dependency. You can pass any Proguard option to it inside importClasses's configuration block by calling option(<rule>)

Binding to SourceSets and Android's Variants

By default, the plugin will bind with the main SourceSet, and works with java and android plugins. Further specific imports can be done by creating new specs matching a Java SourceSet or an Android Variant name

You can configure multiple (and isolated) importClasses through the DSL:

importClasses {
    specs {
        create("debug") {  // will be imported onto Android's `debug` source set only
            dependencies("org.foo:foo:1.0.0")
            repackageTo = "org.foo.another.imported"
            keep("org.foo.AnotherClass")
        }
    }
}

About

A Gradle plugin to import and repackage dependencies `Proguard` tool

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors