Gradle插件<第四篇>:Gradle 7.0配置

本章节是Gradle插件<第一篇>:自定义插件的补充。

在Gradle 7.0 中,如果要做一个插件,配置会有所变化。
完整的配置如下:

plugins {
    id 'java-gradle-plugin'  // Gradle开发插件
    id 'maven-publish'       // 插件发布
    id 'groovy'              // 使用Groovy
}

dependencies {
    implementation "com.android.tools.build:gradle:7.2.1"
}

gradlePlugin {
    plugins {
        MethodTracer {
            id = 'com.nobugexception.routerplugin.register'            //定义插件id
            version = '1.0'
            implementationClass = 'com.nobugexception.routerplugin.register.launch.PluginLaunch'  //定义插件实现类
        }
    }
}

// 本地发布
publishing {
    // 定义发布什么
    publications {
        plugin(MavenPublication) {
            from components.java //使用默认的配置生成jar包
            groupId = 'com.nobugexception'
            artifactId = 'router-register'
            version = '1.0'
        }
    }
    repositories {
        maven {
            // name = 'repo'
            // url = layout.buildDirectory.dir("repo") // 发布到 router-gradle-plugin/build/repo
            url = uri('../router-register') // 发布到项目根目录
        }
    }
}


//远程发布, 发布到我自己的私有库
//publishing {
//    publications {
//        maven(MavenPublication) {
//            groupId = "com.sand.group"
//            artifactId = "mt"
//            version = "1.0.2"
//            description "MTPlug is a good apm tool"
//            from components.java
//        }
//    }
//
//    repositories {
//        maven {
//            allowInsecureProtocol true
//            url = 'http://161.117.195.45:6677/repository/sand_repo/'
//            credentials {
//                it.username = "username"
//                it.password = "pwd"
//            }
//        }
//    }
//}

有一点需要注意:

一般情况下,一个插件的resources文件夹是必不可少的,但是如果在gradle中配置了:

gradlePlugin {
    plugins {
        MethodTracer {
            id = 'com.nobugexception.routerplugin.register'            //定义插件id
            version = '1.0'
            implementationClass = 'com.nobugexception.routerplugin.register.launch.PluginLaunch'  //定义插件实现类
        }
    }
}

就不需要再创建resources文件夹了。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容