自定义gradle插件并发布(部署)到本地

由于项目需要用到热修复,自定义了一个gradle插件用于热修复,但又不想发布到maven,只打算在本地使用(还是会上传到公司git服务器),那么这篇文章就是你想要的!

DemoProject/buildsrc/build.gradle 

apply plugin: 'groovy'
apply plugin: 'maven'

dependencies {
    compile 'com.android.tools.build:gradle:2.3.3'
    compile 'org.javassist:javassist:3.20.0-GA'
    compile gradleApi()
    compile localGroovy()
}

repositories {
    jcenter()
}

uploadArchives {
    repositories.mavenDeployer {
        repository(url: uri('../repo'))
        pom.groupId = 'com.lgh.patchplugin'//包名
        pom.artifactId = 'gradleplugin'//在需要引用插件时用到
        pom.version = '1.0.0'
    }
}

以上是buildsrc/build.gradle里面的配置,而对应的resources里面的配置为

DemoProject/buildsrc/src/main/resources/META-INF.gralde-plugins/com.lgh.patchplugin.PatchRegisterPlugin.properties

implementation-class=com.lgh.patchplugin.PatchRegisterPlugin

最后是project根目录下的build.gradle的配置

DemoProject/build.gradle

 buildscript {
    repositories {
        maven {
            url uri('./repo')
        }
        maven { url "https://jitpack.io" }
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.lgh.patchplugin:gradleplugin:1.0.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven {
            url uri('./repo')
        }
        maven { url "https://jitpack.io" }
        jcenter()
        mavenCentral()
    }
}

最重要的配置就是以上这些,那么应用起来就是在具体的gradle里面apply plugin id

DemoProject/lib_rcs/build.gradle 

apply plugin: com.lgh.patchplugin.PatchRegisterPlugin

参考资料:
1.自定义 Gradle 插件
1.自定义gradle插件
2.自定义Gradle插件

你可能感兴趣的:(gradle)