-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle.kts
197 lines (156 loc) · 5.3 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 com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id("java")
id("maven-publish")
id("com.github.johnrengelman.shadow") version ("7.0.0") apply (false)
id("org.cadixdev.licenser") version ("0.6.1")
}
group = "net.labymod.serverapi"
version = System.getenv("VERSION") ?: "0.0.0"
repositories {
mavenCentral()
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.8.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.8.1")
}
val commonOutputDir = "${buildDir}/commonOutput"
tasks.register<Delete>("cleanCommonOutput") {
delete(commonOutputDir)
}
tasks.named("clean") {
dependsOn("cleanCommonOutput")
}
tasks.named("build") {
dependsOn("cleanCommonOutput")
}
subprojects {
plugins.apply("java-library")
plugins.apply("maven-publish")
plugins.apply("org.cadixdev.licenser")
group = rootProject.group
version = rootProject.version
val compile = configurations.create("compile")
val api by configurations
api.extendsFrom(compile)
license {
header(rootProject.file("LICENSE"))
newLine.set(true)
exclude("**/*.yml")
}
repositories {
mavenCentral()
mavenLocal()
maven("https://dist.labymod.net/api/v1/maven/release/")
}
dependencies {
compileOnly("org.jetbrains:annotations:22.0.0")
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
fun adjustArchiveFileName(property: Property<String>) {
var value = property.get()
if (name != "server-common") {
value = value.replace("server-", "")
}
property.set("labymod-server-api-$value")
}
tasks.jar {
dependsOn("updateLicenses")
adjustArchiveFileName(archiveFileName)
fun includeProjectDependencies(config: Configuration, visited: MutableSet<Project>) {
config.dependencies.forEach { dependency ->
if (dependency is ProjectDependency) {
val project = dependency.dependencyProject
if (visited.add(project)) {
from(project.sourceSets["main"].output)
includeProjectDependencies(project.configurations["compile"], visited)
}
}
}
}
if (System.getenv("DEFAULT_BUILD") != "true") {
includeProjectDependencies(configurations["compile"], mutableSetOf())
}
}
tasks.register("sourcesJar", Jar::class) {
archiveClassifier.set("sources")
adjustArchiveFileName(archiveFileName)
from(sourceSets.main.get().allSource)
}
var publishToken = System.getenv("PUBLISH_TOKEN")
if (publishToken == null && project.hasProperty("net.labymod.distributor.publish-token")) {
publishToken = project.property("net.labymod.distributor.publish-token").toString()
}
java {
withSourcesJar()
}
publishing {
publications {
create<MavenPublication>(project.name) {
groupId = project.group.toString()
artifactId = project.name
version = project.version.toString()
from(components["java"])
}
}
repositories {
maven(project.property("net.labymod.distributor-url").toString()) {
name = "LabyMod-Distributor"
authentication {
create<HttpHeaderAuthentication>("header")
}
credentials(HttpHeaderCredentials::class) {
name = "Publish-Token"
value = publishToken
}
}
}
}
tasks.register<Copy>("copyToCommonOutput") {
val commonOutputDir = project.rootProject.buildDir.resolve("commonOutput")
// Copy regular JAR files
val shadowTask = tasks.findByName("shadowJar")
var buildTask = if (shadowTask != null) "shadowJar" else "jar"
from(tasks.named(buildTask).map { it.outputs.files })
// Copy sources JAR files if they exist
// val sourcesJarTask = tasks.findByName("sourcesJar")
// if (sourcesJarTask != null) {
// from(sourcesJarTask.outputs.files)
// }
into(commonOutputDir)
}
tasks.named("build") {
dependsOn("copyToCommonOutput")
}
if (name.startsWith("server-")) {
val isCommon = name == "server-common"
if (!isCommon) {
dependencies {
api(project(":server-common"))
}
}
if (System.getenv("DEFAULT_BUILD") != "true") {
plugins.apply("com.github.johnrengelman.shadow")
if (tasks.findByName("shadowJar") != null) {
tasks.named<ShadowJar>("shadowJar") {
if (isCommon) {
mergeServiceFiles()
} else {
dependsOn(":server-common:shadowJar")
}
adjustArchiveFileName(archiveBaseName)
archiveClassifier.set("")
}
}
tasks.jar {
finalizedBy("shadowJar")
}
}
}
}
tasks.getByName<Test>("test") {
useJUnitPlatform()
}