forked from plusls/plusls-carpet-addition
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbuild.gradle
170 lines (141 loc) · 5.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
import com.replaymod.gradle.preprocess.Node
plugins {
id("fabric-loom").version("${fabric_loom_version}").apply(false)
id("org.ajoberstar.grgit").version("${grgit_version}")
id("com.replaymod.preprocess").version("${preprocessor_version}")
id("me.fallenbreath.yamlang").version("${yamlang_version}").apply(false)
}
preprocess {
Node mc11404 = createNode("1.14.4-fabric", 1_14_04, "mojang")
Node mc11502 = createNode("1.15.2-fabric", 1_15_02, "mojang")
Node mc11605 = createNode("1.16.5-fabric", 1_16_05, "mojang")
Node mc11701 = createNode("1.17.1-fabric", 1_17_01, "mojang")
Node mc11802 = createNode("1.18.2-fabric", 1_18_02, "mojang")
Node mc11902 = createNode("1.19.2-fabric", 1_19_02, "mojang")
Node mc11903 = createNode("1.19.3-fabric", 1_19_03, "mojang")
Node mc11904 = createNode("1.19.4-fabric", 1_19_04, "mojang")
Node mc12001 = createNode("1.20.1-fabric", 1_20_01, "mojang")
Node mc12002 = createNode("1.20.2-fabric", 1_20_02, "mojang")
Node mc12004 = createNode("1.20.4-fabric", 1_20_04, "mojang")
Node mc12006 = createNode("1.20.6-fabric", 1_20_06, "mojang")
Node mc12101 = createNode("1.21.1-fabric", 1_21_01, "mojang")
mc11404.link(mc11502, null)
mc11502.link(mc11605, null)
mc11605.link(mc11701, null)
mc11701.link(mc11802, null)
mc11802.link(mc11902, file("versions/mapping-1.18.2-1.19.2.txt"))
mc11902.link(mc11903, null)
mc11903.link(mc11904, null)
mc11904.link(mc12001, null)
mc12001.link(mc12002, file("versions/mapping-1.20.1-1.20.2.txt"))
mc12002.link(mc12004, null)
mc12004.link(mc12006, null)
mc12006.link(mc12101, null)
}
ext {
Map env = System.getenv()
File localPropsFile = file("${rootDir}/local.properties")
if (localPropsFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(localPropsFile))
p.each { key, value ->
ext[key as String] = value
}
}
getEnv = {
return env
}
getOrDefault = { String key, String defaultValue ->
String value
(value = project.findProperty(key)) && !value.isEmpty() ? value : defaultValue
}
isGithubCI = {
return env.get("GITHUB_ACTION") != null
}
isJitpack = {
return env.get("JITPACK") != null
}
getBuildNumber = {
return env.GITHUB_RUN_NUMBER ? env.GITHUB_RUN_NUMBER : 0
}
getVersionGit = { List paths ->
if (grgit == null || grgit.head() == null) {
return "nogit"
}
List latestCommits = paths.isEmpty() ? grgit.log(maxCommits: 1) : grgit.log(paths: paths, maxCommits: 1)
return latestCommits.isEmpty() ? "uncommited" : "${latestCommits.get(0).id.substring(0, 7)}"
}
getVersionType = {
String type = getOrDefault("ow.build.environment.buildType", null)
if (type != null) {
return type
}
if (isJitpack()) {
return "jitpack"
}
type = env.BUILD_TYPE
switch (type) {
case "RELEASE":
return "stable"
case "BETA":
return "beta"
case "PULL_REQUEST":
return "pull_request"
default:
return "dev"
}
}
getVersionPatch = { List paths ->
if (grgit == null || grgit.head() == null) {
return 0
}
List latestCommits = paths.isEmpty() ? grgit.log() : grgit.log(paths: paths)
return latestCommits.size()
}
getVersion = { Project proj ->
return "${proj.property("mod.version")}.${getVersionPatch(proj == rootProject ? [] : [proj.projectDir.name])}"
}
getVersionWithCommitHash = { Project proj ->
return "${getVersion(proj)}+${getVersionGit(proj == rootProject ? [] : [proj.projectDir.name])}-${getVersionType()}"
}
getModVersion = { Project proj ->
return "${getVersion(proj)}-${getVersionType()}"
}
getMavenArtifactVersion = { Project proj ->
return project.getVersionType() == "stable" ? "${getVersion(proj)}" : "${getModVersion(proj)}"
}
}
tasks.register("genLocalProperties") {
it.group("${project.property("mod.id")}")
doFirst {
File localPropsFile = file("${rootDir}/local.properties")
if (localPropsFile.exists()) {
throw new IllegalStateException("local.properties file already generated. If you want to regenerate it, please delete it manually first")
} else {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(localPropsFile))
bufferedWriter.writeLine("# Secrets")
bufferedWriter.writeLine("secrets.gpg.signingKey=")
bufferedWriter.writeLine("secrets.gpg.signingPassword=")
bufferedWriter.writeLine("secrets.mavenCentral.username=")
bufferedWriter.writeLine("secrets.mavenCentral.password=")
bufferedWriter.writeLine("")
bufferedWriter.writeLine("# Overwritten configurations")
bufferedWriter.writeLine("ow.build.environment.local=")
bufferedWriter.writeLine("ow.build.environment.buildType=")
bufferedWriter.writeLine("ow.game.window.width=")
bufferedWriter.writeLine("ow.game.window.height=")
bufferedWriter.writeLine("ow.game.window.username=")
bufferedWriter.close()
project.getLogger().info("local.properties generated successfully!")
}
}
}
tasks.register("cleanPreprocessSources") {
it.group("${project.mod_id}")
doFirst {
subprojects {
def path = project.projectDir.toPath().resolve("build/preprocessed")
path.toFile().deleteDir()
}
}
}