This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
260 lines (209 loc) · 5.87 KB
/
build.gradle
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
254
255
256
257
258
259
260
//file:noinspection All
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.+'
}
}
plugins {
id 'java-library'
id 'maven-publish'
id 'idea'
id 'org.jetbrains.kotlin.jvm'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'org.ajoberstar.grgit' version '5.+'
id 'com.matthewprenger.cursegradle' version '1.+'
id 'com.modrinth.minotaur' version '2.+'
}
import com.modrinth.minotaur.dependencies.DependencyType
import com.modrinth.minotaur.dependencies.ModDependency
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
import org.kohsuke.github.GHReleaseBuilder
version = mod_version
group = maven_group
compileKotlin.kotlinOptions.jvmTarget = "17"
repositories {
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases/'
}
maven {
name = 'Jitpack'
url = 'https://jitpack.io/'
}
maven {
name = 'Shedaniel'
url = 'https://maven.shedaniel.me/'
}
}
dependencies {
minecraft "com.mojang:minecraft:$minecraft_version"
mappings "net.fabricmc:yarn:$minecraft_version+build.$yarn_build:v2"
modImplementation "net.fabricmc:fabric-loader:$loader_version"
modImplementation "net.fabricmc.fabric-api:fabric-api:$fabric_version"
include modImplementation ("net.fabricmc:fabric-language-kotlin:$fabric_kotlin_version")
modCompileOnly "com.terraformersmc:modmenu:$mod_menu_version"
testImplementation sourceSets.main.output
}
def githubUsername = System.getenv("GITHUB_USERNAME")
if (githubUsername != null) {
repositories {
maven {
name = 'GitHub Packages (axieum/authme)'
url = 'https://maven.pkg.github.com/axieum/authme/'
credentials {
username = project.findProperty("gpr.user") ?: githubUsername
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
dependencies {
// try get authme, to be able to log into MCC: Island
try {
modRuntimeOnly "me.axieum.mcmod.authme:authme:${project.auth_me_version}"
} catch (exception) {
print("Could not depend on axeium/authme")
exception.printStackTrace()
}
}
}
sourceSets {
test
}
processResources {
inputs.property "version", version
filteringCharset "UTF-8"
filesMatching("fabric.mod.json") {
expand "version": version
}
doLast {
println("Minifying json")
def start = System.currentTimeMillis()
def minified = 0
def bytes = 0
fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
def oldLength = it.length()
it.text = JsonOutput.toJson(new JsonSlurper().parse(it))
bytes += oldLength - it.length()
minified++
}
def ms = System.currentTimeMillis() - start
println("Minified $minified json files. Saved $bytes bytes. Took $ms ms.")
}
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
loom {
accessWidenerPath = file("src/main/resources/${mod_id}.accesswidener")
runs {
server {
ideConfigGenerated = false
}
testClient {
client()
name = "Minecraft Client (Test)"
source sourceSets.test
}
}
}
jar {
from("LICENSE") {
rename { "${it}_${archivesBaseName}" }
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(remapJar) {
builtBy(remapJar)
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
url ENV.MAVEN_URL
allowInsecureProtocol = true
if (ENV.MAVEN_USERNAME) {
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
/* Data Generation */
def generatedResourcesDir = "src/main/generated"
loom {
runs {
create("Data Generation") {
client()
vmArg("-Dfabric-api.datagen")
vmArg("-Dfabric-api.datagen.output-dir=${file(generatedResourcesDir)}")
vmArg("-Dfabric-api.datagen.modid=${mod_id}")
runDir("build/datagen")
}
}
}
sourceSets.main {
resources {
srcDir(generatedResourcesDir)
}
}
/* Releasing */
def ENV = System.getenv()
def VER_NAME = "[$major_version] $mod_name $version"
def CHANGELOG = new File("./gradle", "CHANGELOG.md").text
def SUPPORTED_VERSIONS = Arrays.asList(project.supported_versions.split(','))
tasks.register('github') {
onlyIf { ENV.GITHUB_TOKEN }
dependsOn(build)
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN)
def repository = github.getRepository(project.github_repository)
def builder = new GHReleaseBuilder(repository, version)
builder.name(VER_NAME)
builder.body(CHANGELOG)
builder.commitish(project.github_branch)
builder.prerelease(project.release_type == 'beta')
builder.create().uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
}
}
if (ENV.MODRINTH_TOKEN) modrinth {
token = ENV.MODRINTH_TOKEN
projectId = project.modrinth_id
versionNumber = version
versionName = VER_NAME
versionType = project.release_type
changelog = CHANGELOG
uploadFile = remapJar
gameVersions = SUPPORTED_VERSIONS
dependencies = [ new ModDependency("fabric-api", DependencyType.REQUIRED) ]
}
if (ENV.CURSEFORGE_API_KEY) curseforge {
apiKey = ENV.CURSEFORGE_API_KEY
project {
id = project.curseforge_id
addGameVersion 'Fabric'
for (final def cf_ver in SUPPORTED_VERSIONS) addGameVersion cf_ver
changelog = CHANGELOG
releaseType = project.release_type
mainArtifact(remapJar) {
displayName = VER_NAME
relations {
requiredDependency 'fabric-api'
}
}
afterEvaluate { uploadTask.dependsOn(remapJar) }
}
options { forgeGradleIntegration = false }
}
tasks.register('releaseVersion').configure {
dependsOn(build, 'modrinth', 'github', 'curseforge')
}