generated from wispborne/starsector-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
253 lines (226 loc) · 10.9 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
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
//
// ==============
// ==== SECTION A: RECOMMENDED VARIABLES TO CHANGE ====
/**
* The name of your mod. Used to create a mod folder name (and the name of your mod, if using auto-updated mod_info.json).
* Defaults to the name of the mod's folder.
*/
val modName = "MnemonicUtils"
/**
* Where your Starsector game is installed to.
* Note: On Linux, if you installed Starsector into your home directory, you have to write /home/<user>/ instead of ~/
*/
val starsectorDirectory = if(providers.gradleProperty("starsector.dir").isPresent) providers.gradleProperty("starsector.dir").get() else "/home/jannes/games/starsector"
/** Defaults to the name of your mod, with spaces replaced by hyphens. */
val modFolderName = modName.replace(" ", "-")
//
//
// ==============
// ==== SECTION B: USE ONLY IF AUTOMATICALLY CREATING METADATA FILES (default is not to) ====
/** Set below to `true` to automatically create mod_info.json and Version Checker files. */
val shouldAutomaticallyCreateMetadataFiles = true
// Then, if above is set to true, update the rest of the information below in SECTION B.
val modVersion = "0.3.0"
val jarFileName = "${modName.replace(" ", "-")}.jar"
val modId = "dp_mnemonic_utils"
val modAuthor = "DesperatePeter"
val modDescription = "Offers exploration utility features, such as marking known sensor traces and gates or filtering out worthless loot. Check LunaSettings for details."
val gameVersion = "0.97a"
val jars = arrayOf("jars/$jarFileName")
val modPlugin = "com.dp.mnemonicutils.MnemonicBasePlugin"
val isUtilityMod = true
val masterVersionFile = "https://raw.githubusercontent.com/DesperatePeter/mnemonic-sensors/master/$modId.version"
val modThreadId = "25328"
// If using auto-generated mod_info.json, scroll down to SECTION E.2 and find "THIS FILE IS GENERATED BY build.gradle.kts."
// Update the "dependencies" part of mod_info.json with any mod dependencies to be displayed in the Starsector launcher.
//
//
// ==============
// ==== SECTION C: Game paths, probably won't need to change these unless you're on Unix ====
// Note: On Linux, change the below line to `val starsectorCoreDirectory = "${starsectorDirectory}"`
val starsectorCoreDirectory = "${starsectorDirectory}/starsector-core"
val starsectorModDirectory = "${starsectorDirectory}/mods"
val modInModsFolder = File("$starsectorModDirectory/${modFolderName}")
//
//
//
//
//
// ==============
// ==== SECTION D: DEPENDENCIES/LIBS ====
// The dependencies for the mod to *build* (not necessarily to run).
dependencies {
//////////////////////////////////////////
// SECTION D.1: VANILLA STARSECTOR JARS AND VANILLA DEPENDENCIES
implementation("com.thoughtworks.xstream:xstream:1.4.10")
implementation("org.lwjgl.lwjgl:lwjgl:2.9.3")
implementation("org.lwjgl.lwjgl:lwjgl_util:2.9.3")
implementation("log4j:log4j:1.2.9")
implementation("org.json:json:20090211")
implementation("net.java.jinput:jinput:2.0.7")
implementation("org.codehaus.janino:janino:3.0.7")
implementation("starfarer:starfarer-api:1.0.0") // This grabs local files from the /libs folder, see `repositories` block.
// If the above fails, uncomment this line to use the dependencies in starsector-core instead of getting them from The Internet.
// compileOnly(fileTree(starsectorCoreDirectory) { include("**/*.jar") })
//////////////////////////////////////////
// SECTION D.2: MOD DEPENDENCIES (mods that this mods depends on to compile)
// Uses all mods in /mods folder to compile (this does not mean the mod requires them to run).
// LazyLib is needed to use Kotlin, as it provides the Kotlin Runtime, so ensure that that is in your mods folder.
// IF IT IS TAKING A VERY LONG TIME to index dependencies, try commenting out this `compileOnly` section (which includes ALL mods you have)
// and adding specific mods instead using the `compileOnly` below, just above section D.3.
if (File(starsectorModDirectory).exists()) {
compileOnly(fileTree(starsectorModDirectory) {
include("**/*.jar")
exclude("**/$jarFileName", "**/lib/*", "**/libs/*")
})
} else {
println("$starsectorModDirectory did not exist, not adding mod folder dependencies.")
}
// Add any specific library dependencies needed by uncommenting and modifying the below line to point to the folder of the .jar files.
// All mods in the /mods folder are already included, so this would be for anything outside /mods.
// compileOnly(fileTree("$starsectorModDirectory/modfolder") { include("*.jar") })
//////////////////////////////////////////
// SECTION D.3: KOTLIN DEPENDENCIES
// Shouldn't need to change anything in SECTION D below here
val kotlinVersionInLazyLib = "1.5.31"
// Get kotlin sdk from LazyLib during runtime, only use it here during compile time
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersionInLazyLib")
compileOnly("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersionInLazyLib")
}
// ==============
// ==== SECTION E: GRADLE TASKS ====
// You probably won't ever need to change this *except* to add a specific mod dependency in mod_info.json
tasks {
//////////////////////////////////////////
// SECTION E.1: BUILD A .JAR
named<Jar>("jar")
{
// Tells Gradle to put the .jar file in the /jars folder.
destinationDirectory.set(file("$rootDir/jars"))
// Sets the name of the .jar file.
archiveFileName.set(jarFileName)
}
//////////////////////////////////////////
// SECTION E.2: CREATES & UPDATES METADATA (MOD_INFO.JSON AND VERSION CHECKER) FILES
register("create-metadata-files") {
val version = modVersion.split(".").let { javaslang.Tuple3(it[0], it[1], it[2]) }
System.setProperty("line.separator", "\n") // Use LF instead of CRLF like a normal person
if (shouldAutomaticallyCreateMetadataFiles) {
// Generates a mod_info.json from the variables defined at the top of this script.
File(projectDir, "mod_info.json")
.writeText(
"""
# THIS FILE IS GENERATED BY build.gradle.kts. (Note that Starsector's json parser permits `#` for comments)
{
"id": "${modId}",
"name": "${modName}",
"author": "${modAuthor}",
"utility": "${isUtilityMod}",
"version": { "major":"${version._1}", "minor": "${version._2}", "patch": "${version._3}" },
"description": "${modDescription}",
"gameVersion": "${gameVersion}",
"jars":[${jars.joinToString() { "\"$it\"" }}],
"modPlugin":"${modPlugin}",
"dependencies": [
{
"id": "lw_lazylib",
"name": "LazyLib",
# "version": "2.6" # If a specific version or higher is required, include this line
},
{
"id": "lunalib",
"name": "LunaLib",
},
]
}
""".trimIndent()
)
// Generates a Version Checker csv file from the variables defined at the top of this script.
with(File(projectDir, "data/config/version/version_files.csv")) {
this.parentFile.mkdirs()
this.writeText(
"""
version file
${modId}.version
""".trimIndent()
)
}
// Generates a Version Checker .version file from the variables defined at the top of this script.
File(projectDir, "${modId}.version")
.writeText(
"""
# THIS FILE IS GENERATED BY build.gradle.kts.
{
"masterVersionFile":"${masterVersionFile}",
"modName":"${modName}",
"modThreadId":${modThreadId},
"modVersion":
{
"major":${version._1},
"minor":${version._2},
"patch":${version._3}
},
"directDownloadURL": "https://github.com/DesperatePeter/mnemonic-sensors/releases/download/${version._1}.${version._2}.${version._3}/MnemonicUtils-${version._1}.${version._2}.${version._3}.zip",
"changelogURL": "https://raw.githubusercontent.com/DesperatePeter/mnemonic-sensors/master/changelog.txt"
}
""".trimIndent()
)
}
// Creates a file with the mod name to tell the Github Actions script the name of the mod.
// Not needed if not using Github Actions (but doesn't hurt to keep).
with(File(projectDir, ".github/workflows/mod-folder-name.txt")) {
this.parentFile.mkdirs()
this.writeText(modFolderName)
}
}
//////////////////////////////////////////
// SECTION E.3: COPY TO /MODS
// If enabled, will copy your mod to the /mods directory when run (and whenever gradle syncs).
// Disabled by default, as it is not needed if your mod directory is symlinked into your /mods folder.
register<Copy>("install-mod") {
val enabled = false;
if (!enabled) return@register
println("Installing mod into Starsector mod folder...")
val destinations = listOf(modInModsFolder)
destinations.forEach { dest ->
copy {
from(projectDir)
into(dest)
exclude(".git", ".github", ".gradle", ".idea", ".run", "gradle")
}
}
}
}
//
// ==============
// ==== SECTION F: SOURCE CODE LOCATIONS ====
sourceSets.main {
// Add new folder names here, with the path, if your Java source code isn't in /src.
java.setSrcDirs(listOf("src"))
}
kotlin.sourceSets.main {
// Add new folder names here, with the path, if your Kotlin source code isn't in /src.
kotlin.setSrcDirs(listOf("src"))
// List of where resources (the "data" folder) are.
resources.setSrcDirs(listOf("data"))
}
// ================
// ==== DANGER ====
// -----DON'T TOUCH STUFF BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING -------------------
plugins {
kotlin("jvm") version "1.5.0"
java
}
version = modVersion
repositories {
maven(url = uri("$projectDir/libs"))
mavenCentral()
}
// Compile Kotlin to Java 6 bytecode so that Starsector can use it (options are only 6 or 8)
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.6"
}
// Compile Java to Java 7 bytecode so that Starsector can use it
java.sourceCompatibility = JavaVersion.VERSION_1_7
java.targetCompatibility = JavaVersion.VERSION_1_7