-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
198 lines (176 loc) · 7.52 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
plugins {
id 'java'
id 'checkstyle'
id 'maven-publish'
id 'com.modrinth.minotaur' version '2.2.1'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'fabric-loom' version '0.12-SNAPSHOT'
}
allprojects {
apply plugin: 'java'
apply plugin: 'checkstyle'
apply plugin: 'maven-publish'
apply plugin: 'fabric-loom'
group = project.maven_group
version = project.mod_version
archivesBaseName = "${project.mod_id}-mc${project.minecraft_version}"
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
// Declare dependencies
configurations { devElements { extendsFrom implementation, namedElements } }
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}"
// 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}"
// Subprojects
subprojects.each {
implementation project(path: ":${it.name}", configuration: 'devElements')
include project("${it.name}:") // nest within distribution
}
}
// Perform tests using the JUnit test suite
test {
useJUnitPlatform()
}
// Produce additional distributions
java {
withSourcesJar()
withJavadocJar()
}
// Add the licence to all distributions
tasks.withType(Jar).configureEach {
it.from rootProject.file('LICENCE.txt')
}
// 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])
}
}
// Perform linting using Checkstyle
checkstyle {
configFile rootProject.file('.checkstyle.xml')
toolVersion project.checkstyle_version
}
// Add any additional repositories
repositories {
mavenCentral()
maven { name 'Fabric'; url 'https://maven.fabricmc.net/' }
maven { name 'TerraformersMC'; url 'https://maven.terraformersmc.com/' }
}
// Read the `CHANGELOG.md` for the project version's changelog notes if present
ext.getChangelogNotes = { ->
final File changelog = project.file("CHANGELOG.md")
if (changelog.canRead()) {
def match = changelog.text =~ "(?ms)^## \\[\\Q${project.version}\\E].*?(?=^## |\\Z)"
if (match.find() && !match.group().isBlank()) return match.group().trim()
}
return "For a list of changes, please refer to https://github.com/${project.github_repo}/releases/tag/v${project.version}"
}
// Define how packages are published
publishing {
// Declare all publications
publications {
mavenJava(MavenPublication) { from components.java }
}
// Add repositories to publish to
repositories {
// GitHub Packages (https://pkg.github.com)
maven {
name 'GitHub'
url "https://maven.pkg.github.com/${project.github_repo}"
credentials {
username System.getenv('GITHUB_ACTOR')
password System.getenv('GITHUB_TOKEN')
}
}
}
}
}
// Define how artifacts are published to CurseForge (https://curseforge.com)
curseforge {
// Set the API token from the environment
apiKey System.getenv('CURSEFORGE_TOKEN') ?: ''
// Declare all projects
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 = project.getChangelogNotes()
// Add all supported game versions
project.cf_game_versions.split(', ').each { addGameVersion it }
// Add the main artifact
mainArtifact(remapJar) { displayName = "${project.mod_name} v${project.version} for Minecraft ${project.minecraft_version}" }
// Add any additional artifacts
addArtifact remapSourcesJar
addArtifact javadocJar
subprojects.each {
addArtifact it.remapJar
addArtifact it.remapSourcesJar
addArtifact it.javadocJar
}
// 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
debug = System.getenv('CURSEFORGE_DEBUG') as boolean ?: false
}
}
// Define how artifacts are published to Modrinth (https://modrinth.com)
import com.modrinth.minotaur.dependencies.ModDependency
modrinth {
// Set the API token from the environment
token = System.getenv('MODRINTH_TOKEN') ?: ''
// Set whether debug mode is enabled
debugMode = System.getenv('MODRINTH_DEBUG') as boolean ?: false
// Set the project id
projectId = project.mr_project_id
// Set the release name
versionName = "${project.mod_name} v${project.version} for Minecraft ${project.minecraft_version}"
// Set the release type
versionType = project.version.contains('alpha') ? 'alpha' : project.version.contains('beta') ? 'beta' : 'release'
// Set the release version
versionNumber = project.version
// Set the release notes
changelog = project.getChangelogNotes()
// Add all supported mod loaders
loaders = ['fabric']
// Add all supported game versions
project.mr_game_versions.split(', ').each { gameVersions.add it }
// Add the main artifact
uploadFile = remapJar
// Add any additional artifacts
additionalFiles.add remapSourcesJar
additionalFiles.add javadocJar
subprojects.each {
additionalFiles.add it.remapJar
additionalFiles.add it.remapSourcesJar
additionalFiles.add it.javadocJar
}
// Add any dependencies
if (project.mr_relations_required) dependencies.addAll project.mr_relations_required.split(', ').collect { new ModDependency(it, 'required') }
if (project.mr_relations_optional) dependencies.addAll project.mr_relations_optional.split(', ').collect { new ModDependency(it, 'optional') }
if (project.mr_relations_incompatible) dependencies.addAll project.mr_relations_incompatible.split(', ').collect { new ModDependency(it, 'incompatible') }
}
publish.finalizedBy tasks.curseforge, tasks.modrinth