This repository has been archived by the owner on Sep 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.gradle
201 lines (154 loc) · 5.06 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
buildscript { dependencies { classpath 'org.kohsuke:github-api:1.307' } }
plugins {
id 'java-library'
id 'idea'
id 'eclipse'
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.+'
id 'com.matthewprenger.cursegradle' version '1.4.0'
}
/* Setup */
def ENV = System.getenv()
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
tasks.withType(JavaCompile).configureEach { it.options.release = 17 }
String ver = "${project.version_id}+${project.major_version}-fabric"
version = ENV.GITHUB_ACTIONS ? "${ver}.build.${ENV.GITHUB_RUN_NUMBER}" : ver
archivesBaseName = project.mod_id
group = project.maven_group
/* Dependencies */
repositories {
/* Frame */
maven {
name = 'Modding Playground'
url = 'https://raw.githubusercontent.com/moddingplayground/maven/main/'
}
maven {
name = 'Shedaniel'
url = 'https://maven.shedaniel.me/'
}
/* Mod Menu */
maven {
name = 'Terraformers'
url = 'https://maven.terraformersmc.com/releases/'
}
}
dependencies {
minecraft "com.mojang:minecraft:${project.ver_minecraft}"
mappings "net.fabricmc:yarn:${project.ver_minecraft}+build.${project.ver_yarn}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.ver_loader}"
// api
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.ver_fabric}"
modImplementation ("net.moddingplayground.frame:frame-fabric:${project.ver_frame}-fabric") {
exclude module: 'frame-enchantments-v0'
}
// integration
modImplementation "com.terraformersmc:modmenu:${project.ver_mod_menu}"
}
/* Loom */
loom {
runtimeOnlyLog4j = true
}
/* Data Generation */
def dataOutput = 'src/main/generated'
loom {
runs {
datagen {
server()
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file(dataOutput)}"
runDir "build/datagen"
}
}
}
sourceSets { main { resources { srcDirs += dataOutput } } }
/* Resource Processing */
import groovy.json.*
processResources {
// populate fabric.mod.json with defined version property
inputs.property 'version', version
filesMatching('fabric.mod.json') { expand 'version': version }
doLast {
// minify json files
def start = System.currentTimeMillis()
def minif = 0
def bytes = 0
fileTree(dir: outputs.files.asPath, include: '**/*.json').each {
File file = it
minif++
def oldLength = file.length()
file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
bytes += oldLength - file.length()
}
println("Minified $minif json files. Saved $bytes bytes. Took ${System.currentTimeMillis() - start} ms.")
}
}
// add/remove files in jar
jar { from('README.md', 'LICENSE', 'LICENSE_ASSETS') exclude('.cache') }
/* Publishing */
java { withSourcesJar() }
publishing {
publications {
mavenJava(MavenPublication) {
artifact(remapJar) { builtBy remapJar }
artifact(sourcesJar) { builtBy remapSourcesJar }
}
}
}
loom { disableDeprecatedPomGeneration(publishing.publications.mavenJava) }
/* Releasing */
def VER_NAME = "[$project.major_version] $project.mod_name $project.version_id"
def CHANGELOG = new File("./gradle", "CHANGELOG.md").text
def SUPPORTED_VERSIONS = Arrays.asList(project.supported_versions.split(','))
import org.kohsuke.github.*
task github(dependsOn: build) {
onlyIf { ENV.GITHUB_TOKEN }
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 != 'release')
builder.create().uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
}
}
import com.modrinth.minotaur.dependencies.*
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),
new ModDependency("frame-api", DependencyType.REQUIRED),
new ModDependency("presence-footsteps", DependencyType.OPTIONAL)
]
}
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'
requiredDependency 'frame-api'
optionalDependency 'presence-footsteps'
}
}
afterEvaluate { uploadTask.dependsOn(remapJar) }
}
options { forgeGradleIntegration = false }
}
task releaseVersion(dependsOn: [ build, 'github', 'modrinth', 'curseforge' ])