插件開發
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