-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
164 lines (139 loc) · 4.7 KB
/
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
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
//打包: gradlew -x test clean build shadowJar 成功后发布:gradlew -x test publish
//然后登录https://oss.sonatype.org/#stagingRepositories来查看,你的提交在未处理前,是`open`状态,然后点击`Close`按钮;然后等一会点击`Release`来发布
plugins {
id 'com.github.johnrengelman.shadow' version '7.1.0'
id 'java'
id 'maven-publish'
id 'signing' //使用signing plugin做数字签名
}
//密码,GPG签名信息在此文件里,格式如下
/*
ext.'signing.keyId' = '密钥keyId'
ext.'signing.password' = '密钥password'
ext.'signing.secretKeyRingFile' = '私钥keyRingFile路径'
ext.'sonatypeUsername'='sonatype账号'
ext.'sonatypePassword'='sonatype密码'
*/
apply from: rootDir.canonicalPath + '/.gradle/publish.gradle'
defaultTasks 'shadowJar'
group = 'com.github.wjw465150' //Sonatype上的Issue里填写的`Group Id`,可以跟package路径完全不一样
version = "2.12.5"
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
repositories {
mavenLocal()
maven { url "https://maven.aliyun.com/nexus/content/groups/public/" } //优先使用阿里的镜像
mavenCentral()
//flatDir(dirs: file('jarsDerectory'))
}
dependencies {
implementation "com.fasterxml.jackson.core:jackson-core:${project.version}"
implementation "com.fasterxml.jackson.core:jackson-annotations:${project.version}"
implementation "com.fasterxml.jackson.core:jackson-databind:${project.version}"
//或者: compile fileTree(dir: "lib", includes: ["*.jar"])
}
sourceSets {
sourceCompatibility = 1.6
targetCompatibility = 1.6
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
}
javadoc {
// 防止本地打开中文乱码
options.addStringOption("charset", "UTF-8")
failOnError=false
destinationDir = file("${projectDir}/doc-api")
title = "${project.name}"
includes = ['org/wjw/efjson/*']
}
//为项目生成**.jar/**-javadoc.jar/**-sources.jar
task javadocJar(type: Jar, dependsOn: [shadowJar]) {
from javadoc
classifier = 'javadoc'
}
task sourcesJar(type: Jar) {
from sourceSets.main.allSource
classifier = 'sources'
duplicatesStrategy = 'EXCLUDE'
}
shadowJar {
archiveBaseName.set(project.name)
archiveClassifier.set('')
archiveVersion.set(project.version)
relocate 'com.fasterxml.jackson', 'org.wjw.efjson.deps.com.fasterxml.jackson'
exclude 'META-INF/maven/**'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
manifest {
//<--add
attributes "Built-By": "wjw465150@gmail.com"
attributes "Build-Name": "${project.name}"
attributes "Build-Version": "${project.version}"
}
dependsOn javadoc
}
publishing {
// 定义发布什么
publications {
mavenJava(MavenPublication) {
// groupId,artifactId,version,如果不定义,则会按照默认值执行
groupId = project.group
artifactId = project.name
version = project.version
from components.java
artifact sourcesJar
artifact javadocJar
pom {
// 构件名称
// 区别于artifactId,可以理解为artifactName
name = project.name
// 构件描述
description = 'Encapsulates Jackon JSON library, Fast Speed Easy Used Json Lib For java'
// 构件主页
url = 'https://github.com/wjw465150/EasyFastJson'
// 许可证名称和地址
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'Encapsulates Jackon JSON library, Fast Speed Easy Used Json Lib For java'
}
}
// 开发者信息
developers {
developer {
id = 'wjw465150'
name = 'wjw465150'
email = 'wjw465150@gmail.com'
}
}
// 版本控制仓库地址
scm {
url = "https://github.com/wjw465150/EasyFastJson"
connection = "https://github.com/wjw465150/EasyFastJson.git"
developerConnection = "https://github.com/wjw465150/EasyFastJson.git"
}
}
}
}
// 定义发布到哪里
repositories {
maven {
url "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
// 这里就是之前在issues.sonatype.org注册的账号,这些敏感信息为了防止泄露,我放到了`.gradle/publish.gradle`目录下
username sonatypeUsername
password sonatypePassword
}
}
}
}
//为所有的jar包做数字签名
signing {
sign publishing.publications.mavenJava
}