forked from hupeng199/weidentity-java-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
317 lines (277 loc) · 9.01 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
def gradleVer = "4"
if (gradle.gradleVersion.startsWith("6")
|| gradle.gradleVersion.startsWith("5")
|| gradle.gradleVersion.startsWith("4.10")
|| gradle.gradleVersion.startsWith("4.9")
|| gradle.gradleVersion.startsWith("4.8")
|| gradle.gradleVersion.startsWith("4.7")) {
println "Gradle with version >= 4.7 detected"
gradleVer = "5"
} else {
println "Gradle with version < 4.7 detected"
}
// Due to a bug of spotbugs, the following lines have to be defined on top as well
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.github.spotbugs:spotbugs-gradle-plugin:1.6.5"
}
}
apply plugin: 'maven'
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
if (!gradle.startParameter.isOffline()) {
apply plugin: 'checkstyle'
apply plugin: 'jacoco'
apply plugin: "com.github.spotbugs"
apply plugin: 'signing'
}
group 'com.webank'
version = "1.3.0"
// Specify JDK version - may vary in different scenarios
sourceCompatibility = 1.8
targetCompatibility = 1.8
[compileJava, compileTestJava, javadoc]*.options*.encoding = 'UTF-8'
// In this section you declare where to find the dependencies of your project
repositories {
if (!gradle.startParameter.isOffline()) {
mavenLocal()
mavenCentral()
maven {
url "http://maven.aliyun.com/nexus/content/groups/public/"
}
maven { url "https://dl.bintray.com/ethereum/maven/" }
} else {
maven {
url 'dependencies'
}
}
}
List lombok = [
"org.projectlombok:lombok:1.16.14"
]
List logger = [
"org.slf4j:jul-to-slf4j:1.7.10",
"org.apache.logging.log4j:log4j-api:2.1",
"org.apache.logging.log4j:log4j-core:2.1",
"org.apache.logging.log4j:log4j-slf4j-impl:2.1",
"org.apache.logging.log4j:log4j-web:2.1"
]
// junit test
List junit = [
"junit:junit:4.12"
]
List apache_commons = [
"org.apache.commons:commons-collections4:4.1",
"org.apache.commons:commons-lang3:3.5",
"commons-cli:commons-cli:1.3.1"
]
List jmockit = [
"org.jmockit:jmockit:1.9"
]
List json = [
"com.fasterxml.jackson.core:jackson-databind:2.8.8.1",
"com.github.fge:json-schema-validator:2.2.6",
"com.github.reinert:jjschema:1.16"
]
List weidentity_contract = [
"com.webank:weid-contract-java:1.2.3"
]
List mysql_driver = [
"mysql:mysql-connector-java:5.1.44",
"org.apache.commons:commons-dbcp2:2.5.0"
]
List zxing = [
"com.google.zxing:core:3.3.0"
]
configurations {
localDeps
}
dependencies {
localDeps 'org.projectlombok:lombok:1.16.14'
if (gradleVer.startsWith("4")) {
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, weidentity_contract, mysql_driver, zxing
testCompile logger, lombok, apache_commons, json, junit, jmockit
} else {
compile fileTree(dir: 'dist/lib', include: '*.jar')
}
}
if (gradleVer.startsWith("5")) {
if (!gradle.startParameter.isOffline()) {
compileOnly 'org.projectlombok:lombok:1.16.14'
annotationProcessor 'org.projectlombok:lombok:1.16.14'
testAnnotationProcessor 'org.projectlombok:lombok:1.16.14'
testCompileOnly 'org.projectlombok:lombok:1.16.14'
compile logger, apache_commons, json, weidentity_contract, mysql_driver, zxing
testCompile logger, apache_commons, json, junit, jmockit
} else {
compileOnly files('dist/lib/lombok-1.16.14.jar')
annotationProcessor files('dist/lib/lombok-1.16.14.jar')
testAnnotationProcessor files('dist/lib/lombok-1.16.14.jar')
testCompileOnly files('dist/lib/lombok-1.16.14.jar')
compile fileTree(dir: 'dist/lib', include: '*.jar')
}
}
}
sourceSets {
main {
java {
srcDirs = ['src/main/java']
}
resources {
srcDirs = ['src/main/resources']
}
}
test {
java {
srcDirs = ['src/test/java']
}
resources {
srcDirs = ['src/test/resources']
}
}
}
processResources {
exclude '**/**'
}
task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from 'build/docs/javadoc'
}
artifacts {
archives jar
archives sourcesJar
archives javadocJar
}
jar {
baseName = project.name
destinationDir file('dist/app')
archiveName project.name + '-' + version + '.jar'
exclude '**/*.xml'
exclude '**/*.properties'
doLast {
copy {
from file('src/main/resources/')
into 'dist/conf'
}
if (!gradle.startParameter.isOffline()) {
copy {
from configurations.runtime
from configurations.testCompile.allArtifacts.files
from configurations.testCompile
from configurations.localDeps
into 'dist/lib'
}
}
copy {
from file('.').listFiles().findAll { File f -> (f.name.endsWith('.bat') || f.name.endsWith('.sh') || f.name.endsWith('.env')) }
into 'dist'
}
}
}
if (!gradle.startParameter.isOffline()) {
jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
}
check.dependsOn jacocoTestReport
checkstyle {
ignoreFailures false
showViolations true
toolVersion '8.12'
configProperties.projectDir = project.projectDir
checkstyleMain.configFile = new File(project.projectDir, '/config/checkstyle/webank_google_checks.xml')
checkstyleTest.configFile = new File(project.projectDir, '/config/checkstyle/webank_google_checks.xml')
}
tasks.withType(Checkstyle) {
include '**/*.java'
exclude '**/contract/*.java'
reports {
xml.enabled false
html.enabled true
}
}
spotbugs {
ignoreFailures = true
showProgress = true
toolVersion = "3.1.8"
effort = "max"
reportLevel = "low"
excludeFilter = file("${project.rootDir}/config/spotbugs/spotbugs_filter.xml")
}
tasks.withType(com.github.spotbugs.SpotBugsTask) {
reports {
xml.enabled false
html.enabled true
html.stylesheet resources.text.fromFile('config/spotbugs.xsl')
}
}
}
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: System.getenv('SONATYPE_USERNAME'), password: System.getenv('SONATYPE_PASSWORD'))
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots") {
authentication(userName: System.getenv('SONATYPE_USERNAME'), password: System.getenv('SONATYPE_PASSWORD'))
}
pom.project {
name project.name
packaging 'jar'
description 'Java sdk for WeIdentity.'
url 'https://github.com/WeBankFinTech/weid-java-sdk'
scm {
url 'scm:[email protected]:WeBankFinTech/weid-java-sdk.git'
connection 'scm:[email protected]:WeBankFinTech/weid-java-sdk.git'
developerConnection '[email protected]:WeBankFinTech/weid-java-sdk.git'
}
licenses {
license {
name 'GNU Lesser General Public License version 3'
url 'https://opensource.org/licenses/LGPL-3.0'
distribution 'repo'
}
}
developers {
developer {
id 'tonychen'
name 'tonychen'
}
}
}
}
}
}
import org.gradle.plugins.signing.Sign
gradle.taskGraph.whenReady { taskGraph ->
if (taskGraph.allTasks.any { it instanceof Sign }) {
allprojects { ext."signing.keyId" = System.getenv('GPG_KEY_ID') }
allprojects { ext."signing.secretKeyRingFile" = System.getenv('GPG_KEY_LOCATION') }
allprojects { ext."signing.password" = System.getenv('GPG_PASSPHRASE') }
}
// Do not sign archives by default (a local build without gpg keyring should succeed)
if (taskGraph.allTasks.any { it.name == 'build' || it.name == 'assemble' }) {
tasks.findAll { it.name == 'signArchives' || it.name == 'signDocsJar' || it.name == 'signTestJar' }.each { task ->
task.enabled = false
}
}
}
signing
{
required { gradle.taskGraph.hasTask("uploadArchives") }
sign configurations.archives
}