-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
257 lines (210 loc) · 8.21 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
import groovy.json.JsonSlurper
plugins {
id 'java'
id 'maven-publish'
id 'org.tenne.rest' version '0.4.2'
id 'com.github.johnrengelman.shadow' version "8.1.1"
}
apply plugin: 'maven-publish'
static String getGroup() { return "net.cybercake.cyberapi"; }
static URL getWebsite() { return new URL("https://github.com/CyberedCake/CyberAPI"); }
static String getDescription() { return "The new and improved CyberAPI!"; }
static String[] getAuthors() { return new String[]{"CyberedCake"}; }
static int getTargetJavaVersion() { return 17; }
static boolean isTestingEnvironment() { return Boolean.FALSE.booleanValue(); }
static boolean isOffline() { return Boolean.FALSE.booleanValue(); }
def getLatestTag
try {
if(isOffline()) {
throw new IllegalStateException("Offline mode set to 'TRUE'")
}
getLatestTag = new JsonSlurper().parse(new URL("https://api.github.com/repos/CyberedCake/CyberAPI/releases/latest")).tag_name
} catch (Exception exception) {
logger.error "> Error obtaining latest version, exception: " + exception.toString()
getLatestTag = "0"
}
def currentBuild = {
String tagSplit = getLatestTag
try {
return Integer.parseInt(tagSplit)
} catch (NumberFormatException ignored) {
return 0
}
}
// runner or jitpack should add 1
def build = 0
def setBasic = {
try {
build = currentBuild()
String username = System.getProperty("user.name")
if (username == "runner") { // check if github is building the plugin
if (build <= 1) throw new RuntimeException("Provided build information is incorrect, will not allow build since using GitHub Runner!")
build = build+1
println '> Found using GitHub Runner, going to increment build (' + String.valueOf(build-1) + ' -> ' + String.valueOf(build) + ')'
}
} catch (Exception exception) {
logger.error '> Exception, an error occurred: ' + exception.toString()
}
}
setBasic()
group = getGroup()
version = String.valueOf(build)
def actualVersion = version
def javaVersion = JavaVersion.toVersion(getTargetJavaVersion())
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
logger.quiet("> Found version " + version.toString() + " and build #" + build.toString())
subprojects { Project subProject ->
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'com.github.johnrengelman.shadow'
group = getGroup()
version = this.version
String fileName = "cyberapi-" + getProject().getName() + "-b" + build.toString();
java {
withJavadocJar()
withSourcesJar()
}
tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}
tasks.register('copyArtifacts') {
doLast {
def NEW_DIR = "${getRootProject().buildDir}/artifacts"
def SRC_DIR = "${buildDir}/libs"
ant.copy(todir: NEW_DIR) {
fileset(dir: SRC_DIR,
includes: "**/cyberapi-*.jar"
)
}
}
}
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.register('createProperties') {
doLast {
File file = new File(this.getBuildDir().getAbsolutePath() + File.separator + getProject().getName() + "-build.properties");
if (!file.exists()) {
file.getParentFile().mkdirs()
file.createNewFile()
}
file.withWriter { writer ->
Properties properties = new Properties()
properties['name'] = getProject().getName()
properties['buildFile'] = getBuildFile().getName()
properties['website'] = getWebsite().toString()
properties['user'] = System.getProperty("user.name")
properties['currentJavaVersion'] = System.getProperty("java.version")
properties['currentJavaVendor'] = System.getProperty("java.vendor")
properties['builderOS'] = System.getProperty("os.name")
properties['builderArch'] = System.getProperty("os.arch")
properties['builderVersion'] = System.getProperty("os.version")
properties['task'] = name
properties['group'] = getGroup()
properties['targetJavaVersion'] = String.valueOf(getTargetJavaVersion())
properties['built'] = new Date().toInstant().toEpochMilli().toString()
properties['buildNumber'] = String.valueOf(build)
properties['version'] = String.valueOf(actualVersion)
properties['description'] = this.getDescription()
properties['testingEnvironment'] = isTestingEnvironment().toString()
properties['offline'] = isOffline().toString()
properties.store writer, "CyberAPI Build Information {project: " + getProject().getName() + "}\n(all information from the computer that built CyberAPI)"
}
}
}
artifacts {
archives sourcesJar
archives javadocJar
archives shadowJar
}
repositories {
mavenLocal()
mavenCentral()
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public/'
}
}
javadoc {
configure(options) {
tags(
'apiNote:a"API Note:"',
'implNote:b"Implementation Note:"',
'website:c"Website:"',
'author:d"Author:"'
)
}
}
jar {
sourcesJar.setArchiveFileName("cyberapi-" + getProject().getName() + "-sources-b" + build + ".jar")
javadocJar.setArchiveFileName("cyberapi-" + getProject().getName() + "-javadoc-b" + build + ".jar")
setArchiveFileName("old-jar")
from (this.getBuildDir().getAbsolutePath() + File.separator + getProject().getName() + "-build.properties")
manifest {
attributes 'version': String.valueOf(actualVersion)
attributes 'buildNumber': String.valueOf(build)
}
}
classes {
dependsOn createProperties
}
// if(!subProject.getName().contains("common")) shadowJar.finalizedBy copyArtifacts
publishing {
publications.create("shadow", MavenPublication.class) { publication ->
project.shadow.component(publication)
artifact shadowJar
artifact sourcesJar
artifact javadocJar
groupId = this.getGroup()
artifactId = subProject.getName()
version = String.valueOf(build)
pom {
name = subProject.getName()
version = String.valueOf(build)
url = "https://github.com/CyberedCake/CyberAPI"
developers {
developer {
id = "cybered"
name = "CyberedCake"
}
}
}
}
repositories {
maven {
name = 'sonatype'
url = 'https://repo.cybercake.net/repository/maven-releases/'
credentials {
username = System.getenv("NEXUS_USERNAME")
password = System.getenv("NEXUS_PASSWORD")
}
}
}
}
dependencies {
if (!subProject.getName().contains("common")) {
// cyberapi
implementation project(path: ':common', configuration: 'shadow')
}
}
shadowJar {
dependsOn javadocJar
dependsOn sourcesJar
archiveFileName = "cyberapi-" + getProject().getName() + "-b" + build + ".jar"
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
tasks.withType(Javadoc).configureEach {
options.addStringOption("Xdoclint:none", '-quiet')
}
from (this.getBuildDir().getAbsolutePath() + File.separator + getProject().getName() + "-build.properties")
manifest {
attributes 'version': String.valueOf(actualVersion)
attributes 'buildNumber': String.valueOf(build)
}
}
shadowJar.finalizedBy copyArtifacts
}
wrapper {
gradleVersion = "8.0.1"
distributionType = Wrapper.DistributionType.ALL
}