This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-upload.gradle
161 lines (145 loc) · 5.72 KB
/
build-upload.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*
* MAVEN上传(中心库/私有库/本地库)
*
* 必须:在C:\Users\<user>\.gradle\gradle.properties中配置如下信息
* signing.keyId=XXXXXXXX(gpg -K 查看私钥ID)
* signing.password=XXXXXXXX(私钥保存的秘钥)
* signing.secretKeyRingFile=C:/Users/<user>/AppData/Roaming/gnupg/secring.gpg
* sonatype_user=sonatype用户名
* sonatype_password=sonatype密码
*
* 可选:私有库配置
* private_release_url=私有库RELEASE地址
* private_snapshot_url=私有库SNAPSHOT地址
* private_user=私有库用户名
* private_password=私有库密码
*
* 在gradle-local.properties中选择上传到中心库还是本地库
*
* 发布到指定库: gradlew publish
* 发布到~/.m2库: gradlew publishToMavenLocal
*
* 参考文档:https://docs.gradle.org/current/userguide/publishing_maven.html
* 参考文档:https://docs.gradle.org/current/userguide/signing_plugin.html#signing_plugin
*/
// 库模块/BOM模块
configure(subprojects.findAll { it.PROJECT_GROUP in ['library'] }) {
apply plugin: 'maven-publish'
apply plugin: 'signing'
publishing {
publications {
mavenJava(MavenPublication) {
groupId = project.group
// 构建名默认是子工程名, 也可以在子工程的gradle.properties中配置upload_artifact_id来指定构建名
artifactId = project.hasProperty('upload_artifact_id') ? project.upload_artifact_id : project.name
version = project.version
// 配置: 此处可以配置POM信息
pom {
name = project.name
description = 'An implementation of Java Service Provider Interface'
url = 'https://github.com/shepherdviolet/glaciion'
licenses {
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'shepherdviolet'
name = 'Shepherd Violet'
email = 'shepherdviolet@163.com'
}
}
scm {
connection = 'scm:git@github.com:shepherdviolet/glaciion.git'
developerConnection = 'git@github.com:shepherdviolet/glaciion.git'
url = 'scm:git@github.com:shepherdviolet/glaciion.git'
}
}
}
}
repositories {
// 配置: 此处可配置仓库地址
maven {
if (upload_target == 'maven') {
// 中央库
def releasesRepoUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
def snapshotsRepoUrl = 'https://oss.sonatype.org/content/repositories/snapshots/'
url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = sonatype_user
password = sonatype_password
}
} else if (upload_target == 'private') {
// 私有库, 例如: http://localhost:8081/nexus/content/repositories/reponame/
def releasesRepoUrl = private_release_url
def snapshotsRepoUrl = private_snapshot_url
url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
credentials {
username = private_user
password = private_password
}
} else {
// 本地
def releasesRepoUrl = repository_localRepositoryPath
def snapshotsRepoUrl = repository_localRepositoryPath
url = version.endsWith('-SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
}
}
}
}
if (upload_target != 'local') {
// 签名
signing {
sign publishing.publications.mavenJava
}
}
}
// 库模块
configure(subprojects.findAll { it.PROJECT_GROUP == 'library' }) {
if (upload_target != 'local') {
// 编译时产生源代码jar
task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier.set 'sources'
}
// 编译时产生JAVADOC
task javadocJar(type: Jar) {
from javadoc
archiveClassifier.set 'javadoc'
}
javadoc {
// 禁用JAVA8的JAVADOC检查
if (JavaVersion.current().isJava8Compatible()) {
options.addStringOption('Xdoclint:none', '-quiet')
}
// JAVA9 启用H5文档
if (JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
}
publishing {
publications {
mavenJava(MavenPublication) {
// 添加Java
from components.java
// 添加源码/JavaDoc
if (upload_target != 'local') {
artifact sourcesJar
artifact javadocJar
}
// 自动处理依赖版本
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
}
}