generated from EraTiem-Network/Kotlin-Plugin-Template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
197 lines (161 loc) · 5.65 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
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.stream.Collectors
plugins {
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.shadow)
}
group = "net.eratiem"
version = "1.0.0.alpha1"
subprojects {
this.group = rootProject.group
this.version = rootProject.version
repositories {
bitBuildArtifactory()
rootProject.ext["bitBuildArtifactoryPublish"] = bitBuildArtifactory(useCredentials = true, publish = true)
rootProject.ext["githubPackagesPublish"] = githubPackages(true)
}
apply {
plugin(rootProject.libs.plugins.kotlin.jvm.get().pluginId)
plugin(rootProject.libs.plugins.shadow.get().pluginId)
}
dependencies {
val tools: Project? = findProject(":tools")
if (tools != null && tools != project) implementation(project(path = ":tools", configuration = "shadow"))
compileOnly(rootProject.libs.kotlin.gradleplugin)
compileOnly(rootProject.libs.kotlin.stdlib)
compileOnly(rootProject.libs.minecraft.plugin.eralogger)
}
configurations {
create("shadowJarDependencies").apply {
extendsFrom(project.configurations.implementation.get())
isCanBeResolved = true
}
}
tasks {
shadowJar {
group = "plugin"
enabled = true
dependsOn(classes)
configurations = listOf(
project.configurations.getByName("shadowJarDependencies")
)
archiveBaseName.set(rootProject.name)
archiveClassifier.set(null as String?)
if (project.name != "tools")
archiveAppendix.set(project.name)
}
if (project.name == "tools")
rootProject.ext["toolsArtifact"] = shadowJar
/**
* Copy Task to fill plugin.yml
*/
if (project.name !in arrayOf("tools", "velocity")) {
withType<Copy> {
outputs.upToDateWhen { false }
val mainClass = "${project.group}.${rootProject.name.lowercase()}.${project.properties["mainClass"]}"
val pluginDescription: String by project
val pluginDependencies = getAsYamlList(project.properties["pluginDependencies"])
val pluginSoftDependencies = getAsYamlList(project.properties["pluginSoftdependencies"])
val authors: String = getAsYamlList(project.properties["authors"])
val props: LinkedHashMap<String, String> = linkedMapOf(
"plugin_name" to rootProject.name,
"plugin_description" to pluginDescription,
"plugin_version" to version.toString(),
"plugin_main_class" to mainClass,
"plugin_dependencies" to pluginDependencies,
"plugin_softdependencies" to pluginSoftDependencies,
"plugin_authors" to authors
)
filesMatching("plugin.yml") {
val api = when (project.name) {
"spigot" -> rootProject.libs.versions.plugin.spigot
"paper" -> rootProject.libs.versions.plugin.paper
"folia" -> rootProject.libs.versions.plugin.folia
"bungeecord" -> rootProject.libs.versions.plugin.bungeecord
else -> rootProject.libs.versions.plugin.waterfall
}
props["plugin_api_version"] = api.get()
expand(props)
}
}
}
// Disable standard jar task
jar {
enabled = false
}
// Compile Stuff
val javaVersion = JavaVersion.VERSION_17
withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(javaVersion.toString().toInt())
}
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(javaVersion.toString()))
}
withType<KotlinCompile> {
kotlinOptions.jvmTarget = javaVersion.toString()
}
}
}
fun getAsYamlList(commaSeparatedList: Any?): String =
if (commaSeparatedList is String && commaSeparatedList.isNotBlank()) {
commaSeparatedList
.replace(" ", "")
.split(",")
.stream()
.map { "\n - $it" }
.collect(Collectors.joining())
} else ""
repositories {
bitBuildArtifactory()
}
tasks {
// Disable standard jar task
jar {
enabled = false
}
shadowJar {
enabled = false
}
}
fun RepositoryHandler.bitBuildArtifactory(
useCredentials: Boolean = false, publish: Boolean = false
): MavenArtifactRepository {
val url: String
val name: String
if (publish) {
val nonReleaseStrings = listOf("snapshot", "alpha", "beta", "rc")
val isNonRelease =
nonReleaseStrings.any { project.version.toString().contains(it, true) }
url = "https://artifactory.bit-build.de/artifactory/eratiem${if (isNonRelease) "-snapshots" else ""}"
name = "BitBuildArtifactoryEraTiem${if (isNonRelease) "Snapshots" else ""}"
} else {
url = "https://artifactory.bit-build.de/artifactory/public"
name = "BitBuildArtifactoryPublic"
}
return if (publish || useCredentials) createMavenRepo(url, name, "ARTIFACTORY_USER", "ARTIFACTORY_TOKEN")
else createMavenRepo(url, name)
}
fun RepositoryHandler.githubPackages(useCredentials: Boolean = true): MavenArtifactRepository {
val url = "https://maven.pkg.github.com/EraTiem-Network/${project.name}"
val name = "GitHub"
return if (useCredentials) createMavenRepo(url, name, "GITHUB_USER", "GITHUB_TOKEN")
else createMavenRepo(url, name)
}
fun RepositoryHandler.createMavenRepo(url: String, name: String) = maven {
this.url = uri(url)
this.name = name
}
fun RepositoryHandler.createMavenRepo(url: String, name: String, userEnv: String, passEnv: String) = maven {
this.url = uri(url)
this.name = name
val user: String? = System.getenv(userEnv)
val pass: String? = System.getenv(passEnv)
if (user == null || pass == null) {
logger.error("The environment variable $userEnv or $passEnv does not exist or is null!")
}
credentials {
username = System.getenv(userEnv)
password = System.getenv(passEnv)
}
}