forked from JDA-Applications/JDA-Utilities
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
268 lines (219 loc) · 7.38 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
/*
* Copyright 2016-2021 John Grosh (jagrosh) & Kaidan Gustave (TheMonitorLizard)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.apache.tools.ant.filters.ReplaceTokens
plugins {
id 'maven-publish'
id 'com.github.ben-manes.versions' version '0.17.0'
id 'com.github.johnrengelman.shadow' version '2.0.2'
}
def versionInfo = [major: '3', minor: '1', revision: '0']
task build {
group = 'build'
}
allprojects {
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
group = 'com.jagrosh'
version = versionInfo.values().join('.')
ext {
jdaVersion = '5.1.2'
slf4jVersion = '1.7.25'
okhttpVersion = '3.13.0'
findbugsVersion = '3.0.2'
jsonVersion = '20160810'
junitVersion = '4.13.1' // TODO Move to junit 5?
dependencies {
jda = { [group: 'net.dv8tion', name: 'JDA', version: jdaVersion] }
slf4j = { [group: 'org.slf4j', name: 'slf4j-api', version: slf4jVersion] }
okhttp = { [group: 'com.squareup.okhttp3', name: 'okhttp', version: okhttpVersion] }
findbugs = { [group: 'com.google.code.findbugs', name: 'jsr305', version: findbugsVersion] }
json = { [group: 'org.json', name: 'json', version: jsonVersion] }
junit = { [group: 'junit', name: 'junit', version: junitVersion] }
artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase()
moduleName = "${group}.jdautilities${rootProject == project? "" : ".${project.name.toLowerCase()}"}"
}
// Helper task that allows us to do a one-line method call to fully
//configure a jar task. This prevents possible build inconsistencies.
configureJar = { Object jarConfig, String classifier = '' ->
jarConfig.baseName = "$project.artifactId"
jarConfig.version = "$project.version"
jarConfig.classifier = classifier
jarConfig.extension = 'jar'
jarConfig.manifest {
it.attributes(
'Implementation-Title': project.artifactId,
'Implementation-Version': project.version,
'Automatic-Module-Name': "${project.moduleName}"
)
}
}
// Similar to the extension above, helps keep javadoc
//characteristics consistent between artifacts.
configureJavadoc = { Object jDocConfig ->
jDocConfig.options {
it.author()
it.encoding = 'UTF-8'
it.memberLevel = JavadocMemberLevel.PROTECTED
it.tags 'apiNote:a:API Note:', 'implSpec:a:Implementation Requirements:', 'implNote:a:Implementation Note:'
}
}
}
// Create dependency shortcut for every subproject
rootProject.subprojects.forEach { subproject ->
project.ext."$subproject.name" = { project(":$subproject.name") }
}
repositories {
mavenLocal()
mavenCentral()
maven {
url "https://m2.dv8tion.net/releases"
}
}
build {
// These have to be run in closures
//because they are defined later in the buildscript.
// Trying to specify these at "script-refresh" time
//will cause the refresh to fail.
dependsOn { javadocJar }
dependsOn { sourceJar }
dependsOn { shadowJar }
}
publishing {
publications {
maven(MavenPublication) {
it.groupId = project.group
it.artifactId = project.artifactId
it.version = project.version
}
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'com.github.ben-manes.versions'
ext {
// Allow for individual modules to be marked as excluded
//from the collective artifact (IE: jda-utilities)
includeInParent = true
}
sourceSets {
// add main classpath to test classpath
test {
java.srcDirs += 'src/test/java'
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}
task sourcesForRelease(type: Copy) {
from('src/main/java') {
filter(ReplaceTokens, tokens: [
VERSION_MAJOR: versionInfo.major,
VERSION_MINOR: versionInfo.minor,
VERSION_REVISION: versionInfo.revision
])
}
into 'build/filteredSrc'
}
compileJava {
source = sourcesForRelease.destinationDir
classpath = sourceSets.main.compileClasspath
dependsOn sourcesForRelease
}
javadoc {
destinationDir = file("$buildDir/docs/")
configureJavadoc(it)
}
jar {
configureJar(it)
}
shadowJar {
configureJar(it, 'all')
}
task javadocJar(type: Jar) {
group = 'build'
dependsOn javadoc
from javadoc.destinationDir
configureJar(it, 'javadoc')
}
task sourceJar(type: Jar) {
group = 'build'
dependsOn classes
from sourceSets.main.allSource
configureJar(it, 'sources')
}
publishing {
publications {
maven(MavenPublication) {
from components.java
artifact javadocJar
artifact sourceJar
}
}
}
afterEvaluate {
if(project.includeInParent) {
rootProject.dependencies.compile project
}
}
}
configurations {
compile {
description = 'compile'
transitive = true
}
}
task javadoc(type: Javadoc) {
group = 'documentation'
dependsOn { subprojects*.getTasksByName('javadoc', true) }
source = { subprojects*.sourceSets.main.allJava }
classpath = files(subprojects*.javadoc.classpath)
destinationDir = file("$buildDir/docs/")
configureJavadoc(it)
}
// Jar tasks
task jar(type: ShadowJar) {
group = 'build'
configureJar(it)
from { subprojects*.jar }
destinationDir = file("$buildDir/libs/")
}
task shadowJar(type: ShadowJar) {
group = 'shadow'
dependsOn { rootProject.getTasksByName('jar', true) }
it.configurations += configurations.runtime
configureJar(it, 'all')
from { subprojects*.jar }
destinationDir = file("$buildDir/libs/")
}
task javadocJar(type: Jar) {
group = 'build'
dependsOn { tasks.javadoc }
configureJar(it, 'javadoc')
from { javadoc.destinationDir }
destinationDir = file("$buildDir/libs/")
}
task sourceJar(type: Jar) {
group = 'build'
dependsOn { rootProject.getTasksByName('classes', true) }
configureJar(it, 'sources')
from { subprojects*.sourceSets.main.allSource }
destinationDir = file("$buildDir/libs/")
}
task clean(type: Delete) {
group = 'build'
delete = buildDir
}