-
Notifications
You must be signed in to change notification settings - Fork 0
/
publish-jar-2-local-maven.gradle
165 lines (136 loc) · 4.1 KB
/
publish-jar-2-local-maven.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
162
163
164
165
// ========================================================================
// 发布 *.jar 产物到本地的 maven 仓库.
// ========================================================================
apply plugin: "maven-publish"
apply plugin: "signing"
/**
* 返回仓库的本地路径。
*/
static String getLocalRepositoryDirectory() {
return "/Users/zhp/Workspace/hipoom-maven-2";
}
/**
* 模块名.
*/
static String getProductArtifactId() {
return "registry"
}
/**
* 版本号。
*/
static String getProductVersion() {
return "0.0.3"
}
// 配置签名,上传到 central maven 必须要签名
signing {
sign(publishing.publications)
}
/* ======================================================= */
/* Task Methods */
/* ======================================================= */
/**
* 注册 sourcesJar 任务,否则会没有 sources.jar 文件.
*/
tasks.register('sourcesJar', Jar) {
dependsOn classes
// gradle 8.0 以下用 classifier
// classifier = 'sources'
// gradle 8.0 及以上用 archiveClassifier
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
/**
* 注册 javadocJar 任务,否则会没有 javaDoc.jar 文件.
*/
tasks.register('javadocJar', Jar) {
dependsOn javadoc
// gradle 8.0 以下用 classifier
// classifier = 'javadoc'
// gradle 8.0 及以上用 archiveClassifier
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
// 解决 javadoc 打包乱码,如果提示异常,再次构建即可。
javadoc {
options {
encoding "UTF-8"
charSet 'UTF-8'
author true
version true
title "Hipoom Java Doc"
}
}
publishing {
// 定义目标仓库
repositories {
maven {
url getLocalRepositoryDirectory()
}
}
// 定义产物
publications { PublicationContainer publicationContainer ->
hipoomLocal(MavenPublication) {
// 基本信息
groupId 'com.hipoom'
artifactId getProductArtifactId()
version getProductVersion()
//打包源码和class
from components.java
// 增加 sources.jar 和 javadocs.jar
artifact sourcesJar
artifact javadocJar
// 追加其他信息
pom {
name = "registry"
description = "A utils for java."
url = "https://github.com/hipoom/registry"
licenses {
license {
name = "The Apache License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
}
developers {
developer {
id = "hipoom"
name = "hipoom"
email = "284967632@qq.com"
}
scm {
connection = "no-connection"
developerConnection = "no-developerConnection"
url = "no-url"
}
}
}
}
}
}
}
/* ======================================================= */
/* Private Methods */
/* ======================================================= */
/**
* 获取 local.properties 文件.
* @return File
*/
File getLocalProperties() {
File localProperties = rootProject.file("local.properties")
if (!localProperties.exists()) {
throw new IllegalStateException("[ERROR] 找不到 local.properties 文件.")
}
return localProperties
}
/**
* 从 local.properties 中读取 key 对应的值。
*/
String readLocalProperty(String key) {
File file = getLocalProperties()
InputStream is = file.newDataInputStream()
Properties properties = new Properties()
properties.load(is)
Set<String> keys = properties.stringPropertyNames()
if (!keys.contains(key)) {
return null
}
return properties.getProperty(key)
}