插件开发
gradle插件的开发这里就很少介绍了。你们能够参考smart-doc文档工具官方开源的插件smart-doc-gradle-plugin这个经典例子,这个官方插件比网上普通的gradle插件开发例子技术点全面太多了。java
注册帐号
打开gradle plugin官网,而后点击右上角登陆按钮,而后选择注册,固然也能够直接选择使用github帐号受权登陆,这一步比较简单。git
获取API Keys
以下图,点击右上角的我的帐号,而后进入我的编辑页,而后切换到API Keys的tab,就能够看到对应的内容。 github
已经生成的按照提示复制内容到用户根目录的 ~/.gradle/gradle.properties 文件中,这里是gradle的全局变量的保存位置。 固然也能够本项目的gradle.properties文件中,可是这种方式容易泄露信息,不当心就把key和secret提交了。web
添加插件发布配置
在插件的build.gradle中添加发布配置,以smart-doc官方的smart-doc-gradle-plugin插件为例。maven
buildscript { repositories { maven { url 'http://maven.aliyun.com/nexus/content/groups/public/' } mavenCentral() } } plugins { id 'groovy' id "java" id "java-gradle-plugin" id "com.gradle.plugin-publish" version "0.12.0" } group 'com.github.shalousun' version '1.2.0' sourceCompatibility = 1.8 repositories { maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} mavenCentral() } dependencies { testCompile group: 'junit', name: 'junit', version: '4.13.1' compile 'com.github.shalousun:smart-doc:1.9.6' } tasks.withType(JavaCompile) { options.encoding = "UTF-8" } task javadocJar(type: Jar) { classifier = 'javadoc' from javadoc } task sourcesJar(type: Jar) { classifier = 'sources' from sourceSets.main.allSource } artifacts { archives javadocJar, sourcesJar } gradlePlugin { plugins { greetingsPlugin { id = 'com.github.shalousun.smart-doc' //插件的id implementationClass = 'com.smartdoc.gradle.plugin.SmartDocPlugin' } } } pluginBundle { website = 'https://github.com/smart-doc-group/smart-doc-gradle-plugin' vcsUrl = 'https://github.com/smart-doc-group/smart-doc-gradle-plugin' description = 'smart-doc gradle plugin' //插件描述 tags = ['smart-doc'] //搜索关键词 plugins { greetingsPlugin { // id is captured from java-gradle-plugin configuration displayName = 'smart-doc gradle plugin' } } }
发布插件
在build.gradle完成了发布配置后,在命令行执行命令gradle publishPlugins
而后等待上传结束就发布成功了。ide
固然,添加完成后而且同步后,在idea右侧对应模块的 Tasks 目录下,会多出 plugin portal ,而后点击 publishPlugins 就完成发布了。 工具
gradle成功发布到gradle的插件库后须要等待官方的审核,审核周期大概须要两周,耐心等待审核便可。gradle
使用插件
官方审核经过后就能够经过搜索找到本身的插件,直接查看gradle官方自动给插件生成集成使用操做便可。 ui