-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.gradle
245 lines (204 loc) · 6.32 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
/*
* Copyright (c) Terl Tech Ltd • 04/04/2021, 00:07 • goterl.com
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at http://mozilla.org/MPL/2.0/.
*/
plugins {
id 'java-library'
id 'application'
id 'idea'
id 'com.github.johnrengelman.shadow' version '5.1.0'
id 'signing'
id 'maven'
id 'maven-publish'
id 'biz.aQute.bnd.builder'
}
ext {
artifactId = "resource-loader"
groupId = "com.goterl"
version = '2.0.2'
description = "Resource Loader gives you the functions to load resource files inside or outside JARs."
}
group project.ext.groupId
version = project.ext.version
mainClassName = "com.goterl.resourceloader.Main"
sourceCompatibility = 1.8
targetCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.slf4j:slf4j-api:2.0.0-alpha1"
implementation "net.java.dev.jna:jna:5.9.0"
testImplementation "org.assertj:assertj-core:3.21.0"
testImplementation "org.testng:testng:7.4.0"
testImplementation "org.mockito:mockito-core:4.1.0"
testImplementation "net.jodah:concurrentunit:0.4.6"
testImplementation 'ch.qos.logback:logback-classic:1.2.9'
}
test {
useTestNG()
scanForTestClasses = false
testLogging {
showStandardStreams = true
events "passed", "skipped", "failed"
}
}
jar {
manifest {
attributes(
'Main-Class': 'com.goterl.resourceloader.Main',
"-exportcontents": "com.goterl.resourceloader.*",
"-sources": true
)
}
}
void loadProps() {
File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is ->
p.load(is)
}
p.each { name, value ->
ext[name] = value
}
} else {
ext.isCi = true
}
}
loadProps()
// Return an empty string if a property
// cannot be found
String getProp(String propName) {
return ext.hasProperty(propName) == null ? "" : ext[propName]
}
String getPropBool(String propName) {
return ext.hasProperty(propName) == null ? false : ext[propName]
}
String getSonatypeUserName() {
return findProperty("ossrhUsername")
}
String getSonatypePassword() {
return findProperty("ossrhPassword")
}
boolean isCi() {
return getPropBool("isCi")
}
String getSigningKey() {
return ext.signingKey
}
String getSigningKeyId() {
return ext.signingKeyId
}
String getSigningPassword() {
return ext.signingPassword
}
signing {
useGpgCmd()
sign publishing.publications
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set("sources")
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set("javadoc")
from javadoc.destinationDir
}
task signPom(type: Sign) {
sign project.file("$buildDir/publications/mavenJava/pom-default.xml")
// The signing plugin does not seem to notice
// it when the publications folder with the
// signature has been deleted. So we always
// create a new signature
outputs.upToDateWhen { false }
}
artifacts {
archives sourcesJar, javadocJar
}
Closure createPomClosure = {
def root = asNode()
root.appendNode('description', project.ext.description)
root.appendNode('name', project.ext.artifactId)
root.appendNode('url', 'https://github.com/terl/resource-loader')
def scm = root.appendNode('scm')
scm.appendNode("connection", "scm:git:git://github.com/terl/resource-loader.git")
scm.appendNode("developerConnection", "scm:git:ssh://github.com/terl/resource-loader")
scm.appendNode("url", "http://github.com/terl/resource-loader")
def license = root.appendNode('licenses').appendNode('license')
license.appendNode('name', 'MIT')
license.appendNode('url', 'https://opensource.org/licenses/MIT')
license.appendNode('distribution', 'repo')
def developer = root.appendNode('developers').appendNode('developer')
developer.appendNode('name', 'Terl Tech Ltd')
developer.appendNode('email', '[email protected]')
}
publishing {
publications {
snapshot(MavenPublication) {
from components.java
groupId project.ext.groupId
artifactId project.ext.artifactId
version project.ext.version + "-SNAPSHOT"
artifact sourcesJar
artifact javadocJar
pom.withXml createPomClosure
}
release(MavenPublication) {
from components.java
groupId project.ext.groupId
artifactId project.ext.artifactId
version project.ext.version
artifact sourcesJar
artifact javadocJar
pom.withXml createPomClosure
}
}
repositories {
maven {
name = "release"
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username getSonatypeUserName()
password getSonatypePassword()
}
}
maven {
name = "snapshot"
url = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
credentials {
username getSonatypeUserName()
password getSonatypePassword()
}
}
}
}
// Force character encoding in case the workspace was not set up correctly
tasks.withType(Javadoc) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
// a collection to track failedTests
ext.failedTests = []
afterTest { descriptor, result ->
if (result.resultType == TestResult.ResultType.FAILURE) {
String failedTest = "${descriptor.className}::${descriptor.name}"
logger.debug("Adding " + failedTest + " to failedTests...")
failedTests << [failedTest]
}
}
afterSuite { suite, result ->
if (!suite.parent) { // will match the outermost suite
// logs each failed test
if (!failedTests.empty) {
logger.lifecycle("Failed tests:")
failedTests.each { failedTest ->
logger.lifecycle("${failedTest}")
}
}
}
}
}