-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
236 lines (197 loc) · 6.93 KB
/
build.gradle.kts
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
import java.text.SimpleDateFormat
import java.util.*
plugins {
id("java")
id("java-library")
id("maven-publish")
alias(libs.plugins.blossom)
alias(libs.plugins.shadow)
}
group = compileGroup()
version = compileVersion()
val properties = mapOf(
"pluginVersion" to version,
"pluginName" to project.properties["plugin_name"],
"pluginDescription" to project.properties["plugin_description"],
"pluginWebsite" to project.properties["plugin_website"],
"group" to group
)
repositories {
mavenCentral()
maven("https://jitpack.io/")
maven("https://lib.alpn.cloud/alpine-public/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://repo.helpch.at/releases/")
}
configurations.configureEach {
exclude("org.slf4j")
exclude("junit")
}
dependencies {
// Provided/optional dependencies
compileOnly(libs.spigot.api)
compileOnly(libs.vault.api)
compileOnly(libs.placeholderapi)
compileOnly(libs.gson)
// Bundled dependencies
shade(this, libs.annotations)
shade(this, libs.configlib.spigot)
shade(this, libs.xseries)
shade(this, libs.commons.dbcp2)
shade(this, libs.localelib)
shade(this, libs.bundles.litecommands)
shade(this, libs.bundles.adventure)
// Testing dependencies
testImplementation(libs.testng)
testImplementation(libs.commons.lang)
// Code generation
compileOnly(libs.lombok)
annotationProcessor(libs.lombok)
}
blossom {
properties.forEach {
replaceToken("\${${it.key}}", it.value)
}
}
java {
withSourcesJar()
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
tasks.withType<Jar>().configureEach {
// Rename JAR
archiveFileName.set("${project.properties["plugin_name"]}-$version.jar")
// Add exclusions
exclude("META-INF/versions/")
exclude("META-INF/maven/")
manifest {
attributes(
"Manifest-Version" to "1.0",
"Created-By" to "Gradle",
"Built-JDK" to "${System.getProperty("java.version")} (${System.getProperty("java.vendor")})",
"Built-By" to System.getProperty("user.name"),
"Built-Date" to SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(Date()),
"Name" to project.group.toString().replace(".", "/"),
"Implementation-Title" to project.properties["plugin_name"],
"Implementation-Version" to project.version,
"Implementation-Vendor" to "Crystal Development, LLC.",
"Specification-Title" to project.properties["plugin_name"],
"Specification-Version" to project.version,
"Specification-Vendor" to "Crystal Development, LLC.",
)
}
}
tasks.shadowJar {
dependsOn("jar")
outputs.upToDateWhen { false }
// Add shaded dependencies
configurations.clear()
configurations.add(project.configurations.getByName("shadow"))
// Rename shaded jar
archiveFileName.set("${project.properties["plugin_name"]}-$version-shaded.jar")
}
tasks.build {
dependsOn(tasks.shadowJar)
}
tasks.getByName<Jar>("sourcesJar") {
archiveFileName.set("${project.properties["plugin_name"]}-$version-sources.jar")
}
tasks.withType<JavaCompile>().configureEach {
options.encoding = "UTF-8"
}
tasks.withType<ProcessResources>().configureEach {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
inputs.properties(properties)
filesMatching("plugin.yml") {
expand(properties)
}
from(".") {
include("LICENSE")
into("META-INF/")
}
}
tasks.withType<Test>().configureEach {
useTestNG()
}
publishing {
publications {
create<MavenPublication>("maven") {
// Set the unshaded JAR as the main artifact
artifact(tasks.named("jar"))
// Add sources as secondary artifact
artifact(tasks.named("sourcesJar")) {
classifier = "sources"
}
pom {
name.set(project.properties["plugin_name"] as String)
description.set(project.properties["plugin_description"] as String)
url.set(project.properties["plugin_website"] as String)
groupId = project.properties["maven_group"] as String
artifactId = project.properties["maven_artifact"] as String
version = compileVersion()
packaging = "jar"
withXml {
val dependenciesNode = asNode().appendNode("dependencies")
project.configurations["api"].allDependencies.forEach { dependency ->
if (dependency.name != "LocaleLib") {
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dependency.group)
dependencyNode.appendNode("artifactId", dependency.name)
dependencyNode.appendNode("version", dependency.version)
dependencyNode.appendNode("scope", "compile")
}
}
}
}
}
}
repositories {
maven {
name = "AlpineCloud"
url = uri("https://lib.alpn.cloud" + if (isSnapshot()) "/snapshots" else "/alpine-public")
credentials {
username = System.getenv("ALPINE_MAVEN_NAME")
password = System.getenv("ALPINE_MAVEN_SECRET")
}
}
}
}
tasks.javadoc {
options {
this as StandardJavadocDocletOptions
stylesheetFile = File(projectDir, "/dracula-stylesheet.css")
}
setDestinationDir(File(projectDir, "/docs/"))
include(project.group.toString().replace(".", "/") + "/framework/**/*.java")
include(project.group.toString().replace(".", "/") + "/integration/**/*.java")
include(project.group.toString().replace(".", "/") + "/util/**/*.java")
include(project.group.toString().replace(".", "/") + "/AlpinePlugin.java")
}
tasks.register("writeVersion") {
doLast {
File(".version").writeText(compileVersion())
}
}
subprojects {
tasks.withType<Javadoc>().configureEach {
enabled = false
}
}
fun isSnapshot(): Boolean {
return (project.findProperty("snapshot") as? String)?.toBoolean() ?: false
}
fun compileGroup(): String {
return "${project.properties["maven_group"]}.${project.properties["maven_artifact"]}"
}
fun compileVersion(): String {
val major = project.properties["version_major"]
val minor = project.properties["version_minor"]
val patch = project.properties["version_patch"]
return "${major}.${minor}.${patch}${if (isSnapshot()) "-SNAPSHOT" else ""}"
}
fun <T> shade(scope: DependencyHandlerScope, dependency: Provider<T?>) where T : Any {
scope.implementation(dependency)
scope.api(dependency)
scope.shadow(dependency)
}