-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.gradle
216 lines (180 loc) · 7.65 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 java.util.regex.Matcher
import java.util.regex.Pattern
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
//version = "2.0.3"
group = "com.nicjames2378.IEClocheCompat" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "ieclochecompat"
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
ext.configFile = file "build.properties"
configFile.withReader {
// Load config. It shall from now be referenced as simply config or project.config
def prop = new Properties()
prop.load(it)
project.ext.config = new ConfigSlurper().parse prop
}
dependencies {
// you may put jars on which you depend on in ./libs
// or you may define them like so..
//compile "some.group:artifact:version:classifier"
//compile "some.group:artifact:version"
compile files("libs/ImmersiveEngineering-0.12-88.jar")
compile files("libs/AgriCraft-2.12.0-1.12.0-a6.jar")
// real examples
//compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
//compile 'com.googlecode.efficient-java-matrix-library:ejml:0.24' // adds ejml to the dev env
// the 'provided' configuration is for optional dependencies that exist at compile-time but might not at runtime.
//provided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// the deobf configurations: 'deobfCompile' and 'deobfProvided' are the same as the normal compile and provided,
// except that these dependencies get remapped to your current MCP mappings
//deobfCompile 'com.mod-buildcraft:buildcraft:6.0.8:dev'
//deobfProvided 'com.mod-buildcraft:buildcraft:6.0.8:dev'
// for more info...
// http://www.gradle.org/docs/current/userguide/artifact_dependencies_tutorial.html
// http://www.gradle.org/docs/current/userguide/dependency_management.html
}
if (project.config.verbose.toBoolean()) {
println ""
println ""
println "VERBOSE: Starting extra build sequence."
}
version = getBuildVersion()
setVersionInReferenceJava()
setVersionInBuildProperties()
if (project.config.verbose.toBoolean()) {
println "VERBOSE: Finishing extra build sequence."
println ""
println ""
}
println "Starting build of ${archivesBaseName}. Version: ${version}"
println "Using Forge ${config.forge_version}, for Minecraft ${config.mc_version}"
minecraft {
version = config.mc_version + "-" + config.forge_version
// the mappings can be changed at any time, and must be in the following format.
// snapshot_YYYYMMDD snapshot are built nightly.
// stable_# stables are built at the discretion of the MCP team.
// Use non-default mappings at your own risk. they may not always work.
// simply re-run your setup task after changing the mappings to update your workspace.
mappings = "snapshot_20171003"
runDir = "run"
replace '${mod_version}', project.config.mod_version
makeObfSourceJar = true // an Srg named sources jar is made by default. uncomment this to disable.
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mc_version", project.config.mc_version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': project.version, 'mc_version': project.config.mc_version
}
}
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
def sayVerbose(String text) {
if (project.config.verbose.toBoolean()) {
println("VERBOSE: " + text)
}
}
def getBuildVersion() {
Matcher matchChecker
def returnVersion = project.config.mod_version
sayVerbose("Versioning Started. Current version: " + project.config.mod_version.toString())
String major = ""
String minor = ""
String patch = ""
String dev = ""
sayVerbose("Checking first three segments of version.")
def pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+.*)") // #.#.#-> (through end of line)
matchChecker = pattern.matcher(project.config.mod_version.toString())
if (!matchChecker.matches()) {
println "A version could not be found or is not specified. Please ensure the correct 'build.properties' file is selected and that the 'mod_version' is in the '#.#.#' format (optional '-dev.#')."
}
major = matchChecker.group(1)
sayVerbose("Section 1: " + major)
minor = matchChecker.group(2)
sayVerbose("Section 2: " + minor)
patch = matchChecker.group(3)
sayVerbose("Section 3: " + patch)
pattern = Pattern.compile("(\\d+)\\" + "-(\\w+).(\\d+)")
//#-dev.## (the '+' operation is to correct regex redundant escape character warning caused by the hyphen
matchChecker = pattern.matcher(matchChecker.group(3))
if (matchChecker.matches()) { //if patch version has dev info
sayVerbose("Section 3 has dev information. Dev version: " + matchChecker.group(3))
patch = matchChecker.group(1) //patch is just first part
dev = matchChecker.group(3) //and dev version is 3rd
} else {
sayVerbose("Section 3 does not have dev information.")
}
if (project.config.isDev.toBoolean()) {
sayVerbose("Properties 'inDev' mode enabled.")
if (!matchChecker.matches()) {
sayVerbose("Previous dev version was not detected. Making this version dev.1")
dev = 1
} else {
sayVerbose("Previous dev version was detected. Dev version changing from " + dev + " to " + (dev.toInteger() + 1))
String newDev = (dev.toInteger() + 1)
dev = newDev
}
returnVersion = (major + "." + minor + "." + patch + "-dev." + dev)
} else {
sayVerbose("config is not in dev mode. Patch version changing from " + patch + " to " + (patch.toInteger() + 1))
patch = (patch.toInteger() + 1)
returnVersion = (major + "." + minor + "." + patch)
}
sayVerbose("Versioning Finished. New version: " + returnVersion)
return returnVersion
}
def setVersionInBuildProperties() {
String fileDir = "build.properties"
def file = file(fileDir)
def pattern = Pattern.compile("^mod_version=(.*+)")
def newLines = []
file.eachLine { String s ->
String line = s
def matcher = pattern.matcher(s)
if (matcher.matches()) {
sayVerbose("Found 'mod_version' line in build.properties. Updating string!")
line = line.replace(matcher.group(1), version.toString())
}
newLines.add(line)
}
new File(fileDir).withWriter { out ->
newLines.each {
out.println it
}
}
return 0
}
def setVersionInReferenceJava() {
String fileDir = "src/main/java/com/nicjames2378/IEClocheCompat/utils/Reference.java"
def file = file(fileDir)
def pattern = Pattern.compile("^ {4}public static final String VERSION = \"(\\d.*)\";\$")
//("^ {4}public static final String VERSION = \"([\\d\\.]*)\";\$")
def newLines = []
file.eachLine { String s ->
String line = s
def matcher = pattern.matcher(s)
if (matcher.matches()) {
line = line.replace(matcher.group(1), "${version}")
sayVerbose("Found 'VERSION' line in Reference.java. Updating string!")
}
newLines.add(line)
}
new File(fileDir).withWriter { out ->
newLines.each {
out.println it
}
}
return 0
}