-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
225 lines (190 loc) · 7.31 KB
/
build.gradle.kts
File metadata and controls
225 lines (190 loc) · 7.31 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
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
import java.time.LocalDateTime
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("net.minecraftforge.gradle") version "5.1.+"
id("com.github.johnrengelman.shadow") version "7.1.2"
`maven-publish`
eclipse
idea
}
val mcVersion: String by project
val forgeVersion: String by project
val kotlinVersion: String by project
val coroutinesVersion: String by project
val serializationVersion: String by project
val mockkVersion: String by project
project.group = "com.nubasu.nuchematica"
project.version = "1.0-SNAPSHOT"
val archivesBaseName = "nuchematica"
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(17))
withSourcesJar()
}
jarJar.enable()
minecraft {
mappings("official", mcVersion)
// copyIdeResources.set(true)
runs {
runs {
create("client") {
workingDirectory(project.file("run"))
// ideaModule = "${project.parent!!.name}.${project.name}.test"
workingDirectory(project.file("run"))
args("--noCoreSearch")
property("forge.logging.markers", "SCAN,LOADING,CORE")
property("forge.logging.console.level", "debug")
property("legacy.debugClassLoading", "true")
mods {
create("nuchematica") {
source(sourceSets.main.get())
}
}
}
}
}
}
configurations {
runtimeElements {
setExtendsFrom(emptySet())
}
api {
minecraftLibrary.get().extendsFrom(this)
minecraftLibrary.get().exclude("org.jetbrains", "annotations")
}
}
val shade by configurations.creating
configurations.implementation.get().extendsFrom(shade)
repositories {
maven("https://maven.enginehub.org/repo/")
}
dependencies {
minecraft("net.minecraftforge:forge:1.18.2-40.3.0")
shade("org.jetbrains.kotlin:kotlin-reflect:${kotlin.coreLibrariesVersion}")
shade("org.jetbrains.kotlin:kotlin-stdlib:${kotlin.coreLibrariesVersion}")
shade("org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin.coreLibrariesVersion}")
shade("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
shade("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:${coroutinesVersion}")
shade("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${coroutinesVersion}")
shade("org.jetbrains.kotlinx:kotlinx-serialization-core:${serializationVersion}")
shade("org.jetbrains.kotlinx:kotlinx-serialization-json:${serializationVersion}")
minecraftLibrary("org.jetbrains.kotlin:kotlin-reflect:${kotlin.coreLibrariesVersion}")
minecraftLibrary("org.jetbrains.kotlin:kotlin-stdlib:${kotlin.coreLibrariesVersion}")
minecraftLibrary("org.jetbrains.kotlin:kotlin-stdlib-common:${kotlin.coreLibrariesVersion}")
minecraftLibrary("org.jetbrains.kotlinx:kotlinx-coroutines-core:${coroutinesVersion}")
minecraftLibrary("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:${coroutinesVersion}")
minecraftLibrary("org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:${coroutinesVersion}")
minecraftLibrary("org.jetbrains.kotlinx:kotlinx-serialization-core:${serializationVersion}")
minecraftLibrary("org.jetbrains.kotlinx:kotlinx-serialization-json:${serializationVersion}")
testImplementation("org.junit.jupiter:junit-jupiter:5.9.2")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2")
testImplementation("io.mockk:mockk:${mockkVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.2")
}
val processResources by tasks.getting(Copy::class) {
// this will ensure that this task is redone when the versions change.
inputs.property("version", project.version)
duplicatesStrategy = DuplicatesStrategy.INCLUDE
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.get().resources.srcDirs) {
include("mcmod.info")
// replace version and mcversion
expand(mapOf(
"version" to project.version,
"mcversion" to "1.12.2"
))
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.get().resources.srcDirs) {
exclude("mcmod.info")
}
}
// workaround for userdev bug
val copyResourceToClasses by tasks.creating(Copy::class) {
tasks.classes.get().dependsOn(this)
dependsOn(tasks.processResources)
onlyIf { gradle.taskGraph.hasTask(tasks.getByName("prepareRuns")) }
//into("$buildDir/classes/java/main")
// if you write @Mod class in kotlin, please use code below
into("$buildDir/classes/kotlin/main")
from(tasks.processResources.get().destinationDir)
}
val jar by tasks.getting(Jar::class) {
afterEvaluate {
shade.forEach { dep ->
from(project.zipTree(dep)) {
exclude("META-INF", "META-INF/**")
exclude("LICENSE.txt")
}
from(project.zipTree(dep)) {
include("META-INF/services/**")
}
}
}
duplicatesStrategy = DuplicatesStrategy.INCLUDE
manifest {
attributes(
"Specification-Title" to "nuchematica",
"Specification-Vendor" to "Forge",
"Specification-Version" to "1",
"Implementation-Title" to project.name,
"Implementation-Version" to project.version,
"Implementation-Vendor" to "nubasu.com",
"Implementation-Timestamp" to LocalDateTime.now(),
"Automatic-Module-Name" to "com.nubasu.nuchematica",
)
}
}
tasks.jar.get().finalizedBy("reobfJar")
val shadowModJar by tasks.creating(ShadowJar::class) {
dependsOn("reobfJar")
val basePkg = "com.nubasu.nuchematica.libs"
// add also in FixRtmDevEnvironmentOnlyCorePlugin
relocate("kotlin.", "$basePkg.kotlin.")
relocate("kotlinx.", "$basePkg.kotlinx.")
relocate("io.sigpipe.jbsdiff.", "$basePkg.jbsdiff.")
relocate("org.intellij.lang.annotations.", "$basePkg.ij_annotations.")
relocate("org.jetbrains.annotations.", "$basePkg.jb_annotations.")
relocate("org.apache.commons.compress.", "$basePkg.commons_compress.")
from(provider { zipTree(tasks.jar.get().archiveFile) })
from(fileTree("src/main/distResources")) {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
destinationDirectory.set(buildDir.resolve("shadowing"))
archiveVersion.set("")
manifest.from(provider {
zipTree(tasks.jar.get().archiveFile)
.matching { include("META-INF/MANIFEST.MF") }
.files.first()
})
}
val copyShadowedJar by tasks.creating {
dependsOn(shadowModJar)
doLast {
shadowModJar.archiveFile.get().asFile.inputStream().use { src ->
tasks.jar.get().archiveFile.get().asFile.apply { parentFile.mkdirs() }
.outputStream()
.use { dst -> src.copyTo(dst) }
}
}
}
tasks.assemble.get().dependsOn(copyShadowedJar)
tasks.compileKotlin {
kotlinOptions {
freeCompilerArgs = listOf("-Xexplicit-api=warning", "-Xjvm-default=all")
}
}
val makeSourceDir by tasks.creating {
doLast {
buildDir.resolve("sources/main/java").mkdirs()
}
}
tasks.compileJava.get().dependsOn(makeSourceDir)
publishing {
publications {
register<MavenPublication>("maven") {
from(components["java"])
}
}
}