forked from John-Paul-R/Essential-Commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
318 lines (274 loc) · 11.8 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
plugins {
id 'groovy'
id 'java-gradle-plugin'
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
id "com.modrinth.minotaur" version "2.+"
id 'com.matthewprenger.cursegradle' version "1.4.0"
id "com.github.breadmoirai.github-release" version "2.3.7"
}
build {
dependsOn ':ec-core:build'
}
ext.env = loadenv()
String getenv(String key) {
return env.getOrDefault(key, "NOT FOUND")
}
allprojects {
apply plugin: 'fabric-loom'
apply plugin: 'idea'
group = project.maven_group
String full_version = Boolean.parseBoolean(getenv("IS_PIPELINE"))
? "${project.mod_version}-mc${project.minecraft_version}+${getTimestamp()}"
: "${project.mod_version}-mc${project.minecraft_version}"
version = full_version
archivesBaseName = "${project.mod_id}"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
// Declare dependencies
dependencies {
// Fabric
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
// Mods
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
// modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
modImplementation "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
// Code Quality
compileOnly "org.jetbrains:annotations:${project.jetbrains_annotations_version}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${project.junit_jupiter_version}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${project.junit_jupiter_version}"
// JIJ Dependencies
modApi "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
include "me.lucko:fabric-permissions-api:${project.permissions_api_version}"
modApi "eu.pb4:placeholder-api:${project.placeholder_api_version}"
include "eu.pb4:placeholder-api:${project.placeholder_api_version}"
modImplementation 'org.yaml:snakeyaml:1.33'
include 'org.yaml:snakeyaml:1.33'
modImplementation "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
include "io.github.ladysnake:PlayerAbilityLib:${pal_version}"
// Subprojects
subprojects.each {
implementation project(path: ":${it.name}", configuration: "namedElements")
include project("${it.name}:") // nest within distribution
}
}
// Perform tests using the JUnit test suite
test {
useJUnitPlatform()
}
// Produce a sources distribution
java {
withSourcesJar()
}
// Add the licence to all distributions
tasks.withType(Jar).configureEach {
it.from rootProject.file('LICENCE')
}
// Process any resources
processResources {
inputs.property 'id', project.mod_id
inputs.property 'name', project.mod_name
inputs.property 'version', project.version
// fabric.mod.json
filesMatching('fabric.mod.json') {
expand(['id': project.mod_id, 'name': project.mod_name, 'version': project.version])
}
}
// Add any additional repositories
repositories {
mavenCentral()
maven { name 'Fabric'; url 'https://maven.fabricmc.net/' }
// maven { name 'TerraformersMC'; url 'https://maven.terraformersmc.com/' }
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
maven { url 'https://maven.nucleoid.xyz' }
// Used by FabricPlaceholderAPI
maven {
name = 'Ladysnake Mods'
url = 'https://ladysnake.jfrog.io/artifactory/mods'
content {
includeGroup 'io.github.ladysnake'
includeGroupByRegex 'io\\.github\\.onyxstudios.*'
}
}
}
}
tasks.withType(JavaCompile).configureEach {
// ensure that the encoding is set to UTF-8, no matter what the system default is
// this fixes some edge cases with special characters not displaying correctly
// see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html
// If Javadoc is generated, this must be specified in that task too.
it.options.encoding = "UTF-8"
// Minecraft 1.17 (21w19a) upwards uses Java 16.
it.options.release.set(17)
}
//jar {
// from("LICENSE") {
// rename { "${it}_${project.archivesBaseName}"}
// }
//}
// Define how packages are published
publishing {
// Declare all publications
publications {
mavenJava(MavenPublication) {
artifactId = project.mod_id
groupId = project.maven_group
version = project.version
// Main
artifact(remapJar) { builtBy remapJar }
// Sources
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// Add repositories to publish to
repositories {
// GitHub Packages (https://pkg.github.com)
mavenLocal {
}
maven {
name 'GitHub'
url "https://maven.pkg.github.com/${project.github_repo}"
credentials {
username = getenv('GITHUB_ACTOR')
password = getenv('GITHUB_TOKEN')
}
}
}
}
import com.github.breadmoirai.githubreleaseplugin.GithubReleaseTask
import com.modrinth.minotaur.TaskModrinthUpload
import com.modrinth.minotaur.request.VersionType
modrinth {
token = getenv("MODRINTH") // An environment property called MODRINTH that is your token, set via Gradle CLI, GitHub Actions, Idea Run Configuration, or other
projectId = project.modrinth_project_id
versionNumber = project.version // Will fail if Modrinth has this version already
versionType = project.version.contains('alpha') ? VersionType.ALPHA.toString()
: project.version.contains('beta') ? VersionType.BETA.toString()
: VersionType.RELEASE.toString()
// On fabric, use 'remapJar' instead of 'jar'
uploadFile = remapJar
// This is the java jar task. If it can't find the jar, try 'jar.outputs.getFiles().asPath' in place of 'jar'
gameVersions = List.of(project.mr_game_versions.split(','))
changelog = readChangelogFromFile()
loaders = ['fabric']
// dependencies = {
// var requiredMods = (project.mr_relations_required).split(',').collect { new ModDependency(it, DependencyType.REQUIRED)}
// var optionalMods = (project.mr_relations_optional).split(',').collect { new ModDependency(it, DependencyType.OPTIONAL)}
// var incompatibleMods = (project.mr_relations_incompatible).split(',').collect { new ModDependency(it, DependencyType.INCOMPATIBLE)}
//
// var outList = new ArrayList<ModDependency>(requiredMods.size() + optionalMods.size() + incompatibleMods.size())
// outList.addAll(requiredMods)
// outList.addAll(optionalMods)
// outList.addAll(incompatibleMods)
// return outList
// }()
}
task publishModrinth(type: TaskModrinthUpload) { // Make sure it runs after build!
description 'Uploads all Modrinth projects'
group 'upload'
onlyIf {
// Only attempt to run this task if the MODRINTH variable is set in .env, otherwise SKIP it
env.containsKey("MODRINTH")
}
}
//curseforge475964 // Begin the cursegradle task. Replacing ID with the id you set on the cursegradle config.
curseforge {
apiKey = getenv("CURSEFORGE")
// Declare all projects
//noinspection GroovyAssignabilityCheck
project {
// Set the project id
id = project.cf_project_id
// Set the release type
releaseType = project.version.contains('alpha') ? 'alpha'
: project.version.contains('beta') ? 'beta'
: 'release'
// Set the release notes
changelog = "For a list of changes, please refer to https://github.com/${project.github_repo}/releases/tag/${project.version}"
// Add all supported game versions
project.cf_game_versions.split(',').each { addGameVersion it }
// Add the main artifact
mainArtifact(remapJar) { displayName = "${project.version}" }
// Add any additional artifacts
subprojects.each {
addArtifact it.remapJar
// addArtifact it.sourcesJar
// addArtifact it.jar
}
// Add any dependencies
relations {
if (project.cf_relations_required) project.cf_relations_required.split(',').each { requiredDependency it }
if (project.cf_relations_optional) project.cf_relations_optional.split(',').each { optionalDependency it }
if (project.cf_relations_embedded) project.cf_relations_embedded.split(',').each { embeddedLibrary it }
if (project.cf_relations_tools) project.cf_relations_tools.split(',').each { tool it }
if (project.cf_relations_incompatible) project.cf_relations_incompatible.split(',').each { incompatible it }
}
}
// Configure other options
options {
forgeGradleIntegration = false
}
}
task publishGithubRelease (type: GithubReleaseTask){
description 'Creates a GitHub Release for the project'
group 'upload'
onlyIf {
env.containsKey("GITHUB")
}
}
githubRelease {
token = getenv("GITHUB") // This is your personal access token with Repo permissions
// You get this from your user settings > developer settings > Personal Access Tokens
owner = project.gh_owner // default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
repo = project.gh_repo // by default this is set to your project name
tagName = project.version as String // by default this is set to "v${project.version}"
targetCommitish = "1.19.x" // by default this is set to "master"
releaseName = project.version as String // Release title, by default this is the same as the tagName
body = readChangelogFromFile() // by default this is empty
draft = false // by default this is false
prerelease = false // by default this is false
releaseAssets libsDirectory
.getAsFileTree()
.matching((PatternFilterable pattern) -> pattern.include("**/*${project.version}.jar"))
//jar.outputs.getFiles().asPath//
overwrite = false // by default false; if set to true, will delete an existing release with the same tag and name
dryRun = false // by default false; you can use this to see what actions would be taken without making a release
apiEndpoint = "https://api.github.com" // should only change for github enterprise users
client // This is the okhttp client used for http requests
allowUploadToExisting = false
}
generatePomFileForMavenJavaPublication {}
def static loadenv(String path = ".env") {
def env = [:]
def file = new File(path)
if (file.exists()) {
file.eachLine { line ->
def (name, value) = line.tokenize("=")
env[name.trim()] = value.trim()
}
}
for (el in System.getenv()) {
env[el.key] = el.value;
}
return env
}
String readChangelogFromFile() {
String changelogFilePath = './changelog.md'
var file = new File(changelogFilePath)
if (!file.exists()) {
logger.warn("'%s' not found.", changelogFilePath)
return "changelog file not found"
}
return file.getText('UTF-8')
}
static def getTimestamp() {
return new Date().format('yyyyMMddHHmmss')
}