自定义Gradle Plugin发布到本地

插件build.gradle

采用com.lenebf.plugin插件demo方式。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
/*
* This file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Gradle plugin project to get you started.
* For more details take a look at the Writing Custom Plugins chapter in the Gradle
* User Manual available at https://docs.gradle.org/6.6.1/userguide/custom_plugins.html
*/

plugins {
// Apply the Java Gradle plugin development plugin to add support for developing Gradle plugins
id 'java-gradle-plugin'
// Apply the Groovy plugin to add support for Groovy
id 'groovy'

// 应用 Maven Publish Plugin 发布插件
id 'maven-publish'

id 'com.jfrog.bintray' version "1.8.5"
}

task sourcesJar(type: Jar, dependsOn: classes) {
def classifier = getArchiveClassifier()
classifier.set('sources')
classifier.convention('sources')
from sourceSets.main.allSource
}

publishing {
publications {
apkRename(MavenPublication) {
// 组件类型,我们的插件其实就是Java组件
from components.java
// 插件的组ID,建议设置为插件的包名
groupId = 'com.lenebf.plugin'
// 翻译过来是 工件ID,我的理解是插件的名字
artifactId = 'McImage'
version = '1.5.0'
artifact sourcesJar
// artifact javadocJar
}
}
repositories {
maven {
// $rootProject 表示你项目的根目录
url = "$rootDir/repo"
}
}
}
sourceSets {
main {
groovy {
srcDir 'src/main/groovy'
}
resources {
srcDir 'src/main/resources'
}
}
}
bintray {
user = System.getenv('BINTRAY_USER')
key = System.getenv('BINTRAY_KEY')
publications = ['McImage']
pkg {
// 必填项,前面我们创建的仓库名称
repo = 'maven'

// 必填项,我们要上传的包的名称
name = 'McImage'
// 每次上传直接发布
publish = true

// 开原许可,如果是开源包必须有,否则可选
// 文档原话:your package licenses (mandatory if the package doesn't exist yet and must be created,
// and if the package is an OSS package; optional otherwise)
// licenses = ['Apache-2.0']

// 版本控制系统地址(一般为git地址)如果是开源包必须有,否则可选
// 文档原话:your VCS URL (mandatory if the package doesn't exist yet and must be created,
// and if the package is an OSS package; optional otherwise)
// vcsUrl = 'https://github.com/lenebf/GradlePluginTutorial'

// 包的版本信息
version {
// 必填,版本名称
name = '0.0.6'
// 选填,版本描述
desc = 'McImage Plugin 0.0.6'
// 选填,版本发布日期
released = new Date()
// 选填,版本控制系统的对象的tag名称
vcsTag = 'tag_0.0.6'
// 选填,该版本的附件属性信息,可以任意填写
attributes = ['McImage': 'a simple plugin.']
}
}
}
repositories {
// Use jcenter for resolving dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
gradlePlugin {
// Define the plugin
plugins {
mcImage {
id = 'McImage'
implementationClass = 'com.lenebf.plugin.ImagePlugin'
}
}
}

dependencies {
implementation 'com.android.tools.build:gradle:4.0.2'
}

发布 settings.gradle

include ‘:McImage’

工程 build.gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
buildscript {
repositories {
maven {
url uri('./repo')
}
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.2'
classpath 'com.lenebf.plugin:McImage:1.5.0'
// classpath 'com.smallsoho.mobcase:McImage:1.5.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

allprojects {
repositories {
maven {
url uri('./repo')
}
google()
jcenter()

}
}