-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
197 lines (166 loc) · 5.87 KB
/
build.gradle
File metadata and controls
197 lines (166 loc) · 5.87 KB
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
// You should not need to edit this file directly.
// Use repositories.gradle and dependencies.gradle instead.
import groovy.json.JsonSlurper
plugins {
id "java"
id "com.gradleup.shadow" version "8.3.0"
}
configurations {
internal
}
configurations.implementation.extendsFrom(configurations.internal)
java {
sourceCompatibility = getVersionForMajor(javaSourceVersion)
targetCompatibility = getVersionForMajor(javaTargetVersion)
if (generateSourcesJar.toBoolean()) {
withSourcesJar()
}
if (generateJavadocJar.toBoolean()) {
withJavadocJar()
}
}
// Configure shadowJar task
shadowJar {
configurations = [project.configurations.internal]
enableRelocation = true
relocationPrefix = projectGroup + ".shadow"
}
tasks.compileJava {
options.encoding = "UTF-8"
}
tasks.javadoc {
options.encoding = "UTF-8"
}
repositories {
mavenCentral()
maven {
name = "kettlemc"
url = "https://repo.kettlemc.net/repository/maven-public/"
}
}
// Set group and version from properties
group = projectGroup
version = pluginVersion
// Load version mappings from api-versions.json
if (pluginApi) {
println "Loading api mapping file..."
def versionsUrl = 'https://raw.githubusercontent.com/KettleMC-Network/kTemplate/refs/heads/api-versions/api-versions.json'
def connection = new URL(versionsUrl).openConnection()
connection.setRequestProperty('User-Agent', 'Gradle Script')
def versionMap
try {
def inputStream = connection.getInputStream()
versionMap = new JsonSlurper().parse(inputStream)
inputStream.close()
} catch (Exception e) {
throw new GradleException("Failed to load api-versions.json from remote URL", e)
}
def artifactRepositories = versionMap[pluginApi]?.repositories
if (!artifactRepositories) {
throw new GradleException("Couldn't find repositories for the API '${pluginApi}'")
}
def artifactId = versionMap[pluginApi]?.artifact
if (!artifactId) {
throw new GradleException("Couldn't find artifact ID for the API '${pluginApi}'")
}
def artifactVersion = versionMap[pluginApi]?.versions?.get(minecraftVersion) ?: minecraftVersion
if (!artifactVersion) {
throw new GradleException("Couldn't find a version for the given API '${pluginApi} and Minecraft version: ${minecraftVersion}")
}
def apiAnnotationProcessor = versionMap[pluginApi]?.annotationProcessor
if (apiAnnotationProcessor) {
println "Using annotation processor '${apiAnnotationProcessor}' for API '${pluginApi}'"
dependencies {
annotationProcessor "${apiAnnotationProcessor}:${artifactVersion}".toString()
}
} else {
println "No annotation processor found for API '${pluginApi}'"
}
// Add dynamic repositories for artifact
for (repo in artifactRepositories) {
var repoName = pluginApi.replace(":", "-").replace(".", "-")
println "Adding repository '${repoName}' at '${repo}'"
repositories {
maven {
name = repoName
url = repo
}
}
}
// Add the artifact as a dependency
println "Using artifact '${artifactId}:${artifactVersion}'"
dependencies {
compileOnly "${artifactId}:${artifactVersion}"
}
}
dependencies {
implementation fileTree(dir: "libs/implementation", include: "*.jar")
internal fileTree(dir: "libs/internal", include: "*.jar")
compileOnly "org.jetbrains:annotations:24.0.1"
}
// JASKL dependencies
if (jasklVersion && jasklImplementation) {
if (jasklShadow.toBoolean()) {
dependencies {
internal "io.github.almighty-satan.jaskl:jaskl-${jasklImplementation}:${jasklVersion}"
}
} else {
dependencies {
implementation "io.github.almighty-satan.jaskl:jaskl-${jasklImplementation}:${jasklVersion}"
}
}
}
// SLAMS dependencies
if (slamsVersion && (slamsParser || slamsImplementation)) {
if (slamsShadow.toBoolean()) {
dependencies {
if (slamsParser) internal "io.github.almighty-satan.slams:slams-parser-${slamsParser}:${slamsVersion}"
if (slamsImplementation) internal "io.github.almighty-satan.slams:slams-${slamsImplementation}:${slamsVersion}"
}
} else {
dependencies {
if (slamsParser) implementation "io.github.almighty-satan.slams:slams-parser-${slamsParser}:${slamsVersion}"
if (slamsImplementation) implementation "io.github.almighty-satan.slams:slams-${slamsImplementation}:${slamsVersion}"
}
}
}
// kLanguage dependencies
if (klanguageVersion) {
dependencies {
implementation "net.kettlemc.klanguage:klanguage-core:${klanguageVersion}"
implementation "net.kettlemc.klanguage:klanguage-${klanguageImplementation}:${klanguageVersion}"
implementation 'net.kyori:adventure-text-minimessage:4.14.0'
implementation 'net.kyori:adventure-platform-bukkit:4.3.0'
}
}
// kCommon dependencies
if (kcommonVersion) {
dependencies {
implementation "net.kettlemc:kcommon:${kcommonVersion}"
}
}
// Apply external repository and dependency files if present
if (file("repositories.gradle").exists()) {
apply from: "repositories.gradle"
}
if (file("dependencies.gradle").exists()) {
apply from: "dependencies.gradle"
}
processResources {
outputs.upToDateWhen { false }
duplicatesStrategy = DuplicatesStrategy.INCLUDE
from sourceSets.main.resources.srcDirs
include "**/*.*"
expand(
"name": pluginName,
"version": pluginVersion,
"author": pluginAuthor,
"description": pluginDescription,
"website": pluginWebsite,
"apiversion": pluginApiVersion,
"main": pluginMain
)
}
static def getVersionForMajor(String version) {
return JavaVersion.values().find { it.majorVersion == version }
}