-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
216 lines (178 loc) · 6.9 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
import net.minecraftforge.gradle.common.util.ModConfig
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
mavenCentral()
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1.+', changing: true
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
apply plugin: 'idea'
// Configure all projects
subprojects {
apply plugin: 'net.minecraftforge.gradle'
// Import mod dependencies and execute
// if (file('dependencies.gradle').exists())
// apply from: 'dependencies.gradle'
group = 'net.dandoes.minecraft'
version = getVersionString(project)
archivesBaseName = getArchiveBaseName(project)
compileJava {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8
}
minecraft {
mappings channel: 'official', version: minecraftVersion
ModConfig projectMod = new ModConfig(project, project.moduleModId);
projectMod.source(project.sourceSets.main)
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
// The markers can be changed as needed.
// "SCAN": For mods scan.
// "REGISTRIES": For firing of registry events.
// "REGISTRYDUMP": For getting the contents of all registries.
property 'forge.logging.markers', 'REGISTRIES'
// Recommended logging level for the console
// You can set various levels here.
// Please read: https://stackoverflow.com/questions/2031163/when-to-use-the-different-log-levels
property 'forge.logging.console.level', 'debug'
mods.add(projectMod)
}
server {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
mods.add(projectMod)
}
data {
workingDirectory project.file('run')
property 'forge.logging.markers', 'REGISTRIES'
property 'forge.logging.console.level', 'debug'
// Specify the modid for data generation, where to output the resulting resource, and where to look for existing resources.
args '--mod', project.moduleModId, '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources/')
mods.add(projectMod)
}
}
}
sourceSets.main.resources { srcDir 'src/generated/resources' }
// Common dependencies for all modules
dependencies {
minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:5.2.0"
testCompile("org.junit.jupiter:junit-jupiter-api:5.2.0")
testCompile("org.junit.platform:junit-platform-launcher:1.1.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.2.0")
}
jar {
manifest {
attributes([
"Specification-Title": project.moduleModName,
"Specification-Vendor": "Daniel Schaffer",
"Specification-Version": getBaseSemverString(rootProject),
"Name": "${rootProject.name}/${project.name}",
"Implementation-Title": project.moduleName,
"Implementation-Version": getVersionString(rootProject),
"Implementation-Vendor" :"Daniel Schaffer",
"Implementation-Timestamp": new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
])
}
}
}
evaluationDependsOnChildren()
def clientProjects = subprojects.findAll { sp -> sp.includeWithClient == "true" }
def serverProjects = subprojects.findAll { sp -> sp.includeWithServer == "true" }
println("clientProjects:")
clientProjects.each {
println(" " + it.name)
}
println("serverProjects:")
serverProjects.each {
println(" " + it.name)
}
task copyServerLibJars(type: Copy, dependsOn: subprojects.tasks['reobfJar']) {
from serverProjects.collect {it.tasks.withType(Jar) }
into project.file('build/libs/server').path
}
task copyClientLibJars(type: Copy, dependsOn: subprojects.tasks['reobfJar']) {
from clientProjects.collect { it.tasks.withType(Jar) }
into project.file('build/libs/client').path
}
task copyLibJars {
dependsOn copyServerLibJars, copyClientLibJars
}
task buildLibs {
dependsOn copyLibJars
}
task copyClientRunJars(type: Copy, dependsOn: clientProjects.tasks['jar']) {
from clientProjects.collect { it.tasks.withType(Jar) }
into project.file('run/client/mods').path
}
task copyServerRunJars(type: Copy, dependsOn: serverProjects.tasks['jar']) {
from serverProjects.collect { it.tasks.withType(Jar) }
into project.file('run/server/mods').path
}
task prepareRuns(dependsOn: subprojects.tasks['prepareRuns']) {}
task prepareRunClient() {
clientProjects.each { dependsOn("${it.name}:prepareRunClient") }
dependsOn copyClientRunJars
}
task prepareRunServer() {
serverProjects.each { dependsOn("${it.name}:prepareRunServer") }
dependsOn copyServerRunJars
}
task cleanSubprojects {
subprojects.each {
delete project.fileTree('build/libs').matching {
include "**/*.jar"
}
delete project.fileTree('build/reobfJar').matching {
include "**/*.jar"
}
}
}
task cleanLibs {
dependsOn cleanSubprojects
delete project.fileTree('build/libs').matching {
include "**/*.jar"
}
}
task cleanRun {
delete project.fileTree('build/run').matching {
include "*/mods/**/*.jar"
}
}
String[] getSemver(Project proj) {
def semver = proj.version =~ /^(\d+)\.(\d+)\.(\d+)(?:-(\w+))?$/
def (_, major, minor, patch, tag) = semver[0]
return [major, minor, patch, tag]
}
String getBaseSemverString(Project proj) {
def (major, minor, patch) = getSemver(proj)
return "${major}.${minor}.${patch}"
}
String getVersionString(Project proj) {
def (major, minor, patch, prereleaseQualifier) = getSemver(proj)
String buildQualifier = System.getenv('VERSION_QUALIFIER') ?: 'snapshot'
String qualifier = prereleaseQualifier ?: buildQualifier
String buildId = buildQualifier == 'final' && !prereleaseQualifier ? null : (
System.getenv('BUILD_NUMBER') ?: new Date().format("yyyyMMddHHmmss")
)
def result = "${major}.${minor}.${patch}-${qualifier}"
if (buildId) {
result += ".${buildId}"
}
return result
}
String getPrettyName(Project proj) {
return "${rootProject.name}-${proj.moduleName}"
}
String getArchiveBaseName(Project proj) {
return "${getPrettyName(proj)}-${project.minecraftVersion}"
}