-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle.kts
124 lines (110 loc) · 4.1 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
import java.io.OutputStream
plugins {
kotlin("jvm") version "1.4.21"
id("com.github.johnrengelman.shadow") version "5.2.0"
`maven-publish`
}
val relocate = (findProperty("relocate") as? String)?.toBoolean() ?: true
repositories {
mavenLocal()
mavenCentral()
maven(url = "https://papermc.io/repo/repository/maven-public/")
maven(url = "https://jitpack.io/")
}
dependencies {
compileOnly(kotlin("stdlib"))
compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.1")
compileOnly("com.destroystokyo.paper:paper-api:1.16.4-R0.1-SNAPSHOT")
implementation("com.github.noonmaru:tap:3.2.7")
implementation("com.github.noonmaru:kommand:0.6.4")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.7.0")
testImplementation("org.mockito:mockito-core:3.6.28")
testImplementation("org.spigotmc:spigot:1.16.4-R0.1-SNAPSHOT")
}
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
processResources {
filesMatching("**/*.yml") {
expand(project.properties)
}
}
test {
useJUnitPlatform()
doLast {
file("logs").deleteRecursively()
}
}
create<Jar>("sourcesJar") {
from(sourceSets["main"].allSource)
archiveClassifier.set("sources")
}
shadowJar {
archiveBaseName.set(project.property("pluginName").toString())
archiveVersion.set("") // For bukkit plugin update
archiveClassifier.set("") // Remove 'all'
if (relocate) {
relocate("com.github.noonmaru.kommand", "${rootProject.group}.${rootProject.name}.kommand")
relocate("com.github.noonmaru.tap", "${rootProject.group}.${rootProject.name}.tap")
}
doFirst {
println("relocate = $relocate")
}
}
build {
dependsOn(shadowJar)
}
create<Copy>("paper") {
from(shadowJar)
var dest = file(".paper/plugins")
// if plugin.jar exists in plugins change dest to plugins/update
if (File(dest, shadowJar.get().archiveFileName.get()).exists()) dest = File(dest, "update")
into(dest)
}
create<DefaultTask>("setupWorkspace") {
doLast {
val versions = arrayOf(
"1.16.4"
)
val buildtoolsDir = file(".buildtools/")
val buildtools = File(buildtoolsDir, "BuildTools.jar")
val maven = File(System.getProperty("user.home"), ".m2/repository/org/spigotmc/spigot/")
val repos = maven.listFiles { file: File -> file.isDirectory } ?: emptyArray()
val missingVersions = versions.filter { version ->
repos.find { it.name.startsWith(version) }?.also { println("Skip downloading spigot-$version") } == null
}.also { if (it.isEmpty()) return@doLast }
val download by registering(de.undercouch.gradle.tasks.download.Download::class) {
src("https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar")
dest(buildtools)
}
download.get().download()
runCatching {
for (v in missingVersions) {
println("Downloading spigot-$v...")
javaexec {
workingDir(buildtoolsDir)
main = "-jar"
args = listOf("./${buildtools.name}", "--rev", v)
// Silent
standardOutput = OutputStream.nullOutputStream()
errorOutput = OutputStream.nullOutputStream()
}
}
}.onFailure {
it.printStackTrace()
}
buildtoolsDir.deleteRecursively()
}
}
}
publishing {
publications {
create<MavenPublication>(project.property("pluginName").toString()) {
artifactId = project.name
from(components["java"])
artifact(tasks["sourcesJar"])
}
}
}