-
Notifications
You must be signed in to change notification settings - Fork 384
/
maven_publish.gradle
130 lines (111 loc) · 4.23 KB
/
maven_publish.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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 依赖信息
def groupIdDefined = "com.licheedev"
def artifactIdDefined = "android-serialport"
// 如果是测试版,版本号后面加上 -SNAPSHOT
def versionDefined = rootProject.ext.versionName
// 其他信息
def gitUrl = "https://github.com/licheedev/Android-SerialPort-API"
// 配置是否上传
def toUpload = true
//在根build.gradle中加入,最新版本号参考 https://github.com/Kotlin/dokka#using-dokka
//classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32'
//在module的build.gradle末位加入
//apply from: '../maven_publish.gradle'
if (toUpload) {
apply plugin: 'signing'
apply plugin: 'maven-publish'
apply plugin: 'org.jetbrains.dokka'
//<editor-fold desc="打包源码和javadoc">
// 打包源码
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
task javadoc(type: Javadoc) {
failOnError false
source = android.sourceSets.main.java.sourceFiles
options {
encoding = "utf-8"
charSet 'UTF-8'
}
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
classpath += configurations.compile
}
// 打包javadoc
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}
// 打包包含kotlin源码的javadoc
task kotlinDocJar(type: Jar, dependsOn: dokkaHtml) {
classifier = 'javadoc'
from dokkaHtml.outputDirectory
}
//</editor-fold>
afterEvaluate {
publishing {
publications {
mavenAndroid(MavenPublication) {
from components.release
groupId "$groupIdDefined"
artifactId "$artifactIdDefined"
version "$versionDefined"
// 上传source
artifact sourcesJar
// 上传javadoc
if (project.plugins.hasPlugin('kotlin-android')) {
artifact kotlinDocJar
} else {
artifact javadocJar
}
pom {
name = 'Android-SerialPort-API'
description = 'Android-SerialPort-API'
url = "$gitUrl"
//licenses {
// license {
// name = 'The MIT License'
// url = 'https://opensource.org/licenses/MIT'
// }
//}
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'licheedev'
name = 'John Lee'
email = '[email protected]'
}
}
scm {
connection = "$gitUrl"
developerConnection = "${gitUrl}.git"
url = "$gitUrl"
}
}
}
}
repositories {
maven {
// 依赖发布地址
def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
// 配置账号密码
println "user=${ossrhUsername},key=${ossrhPassword}"
credentials {
username "${ossrhUsername}"
password "${ossrhPassword}"
}
}
}
}
signing {
sign publishing.publications.mavenAndroid
}
}
}