-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.gradle
262 lines (209 loc) · 8.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
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
import com.matthewprenger.cursegradle.CurseArtifact
import net.dumbcode.gradlehook.tasks.form.FieldObject
import net.dumbcode.gradlehook.tasks.form.PostForm
import org.apache.commons.io.FileUtils
import java.time.Instant
import java.time.ZoneOffset
buildscript {
repositories {
jcenter()
maven { url = "http://files.minecraftforge.net/maven" }
maven { url = "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
classpath "gradle.plugin.com.matthewprenger:CurseGradle:1.3.0"
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.8"
classpath "net.dumbcode.gradlehook:GradleHook:1.2.1"
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: "maven-publish"
apply plugin: "com.matthewprenger.cursegradle"
apply plugin: "net.dumbcode.gradlehook"
apply plugin: "org.sonarqube"
//Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
def curseforgeID = "298694"
version = "1.12.2-" + getDirectVersion()
group = "net.dumbcode.dumblibrary" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "dumblibrary"
sourceCompatibility = targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.
compileJava {
sourceCompatibility = targetCompatibility = '1.8'
}
minecraft {
version = "1.12.2-14.23.4.2705"
runDir = "run"
mappings = "stable_39"
}
repositories {
mavenCentral()
maven {
url = "https://maven.mcmoddev.com"
}
maven {
url = "http://dvs1.progwml6.com/files/maven"
}
maven {
name = "CurseForge"
url = "https://minecraft.curseforge.com/api/maven/"
}
}
dependencies {
deobfCompile "mezz.jei:jei_1.12.2:4.9.1.187:api"
runtime "mezz.jei:jei_1.12.2:4.9.1.187"
compile 'org.projectlombok:lombok:1.18.12'
compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.0'
}
sonarqube {
properties {
property "sonar.projectName", "DumbLibrary"
property "sonar.projectKey", "net.dumbcode.dumblibrary"
property "sonar.links.homepage", "https://github.com/Dumb-Code/DumbLibrary"
property "sonar.links.ci", "https://travis-ci.com/Dumb-Code/DumbLibrary"
property "sonar.links.scm", "https://github.com/Dumb-Code/DumbLibrary"
property "sonar.links.issue", "https://github.com/Dumb-Code/DumbLibrary/issues"
}
}
def setDebugCommitVersion() {
def version = "debug-" + System.getenv("TRAVIS_BUILD_NUMBER") + "-" + System.getenv("TRAVIS_COMMIT").substring(0, 7)
def prefix = 'public static final String VERSION = "'
def file = file("src/main/java/net/dumbcode/dumblibrary/DumbLibrary.java")
def text = file.text
file.withWriter { w-> w << text.replaceAll("\\Q$prefix\\E.+\"", prefix + version + '"') }
return version
}
def run(String command, File f = file("Changelogs")) {
def commands = command.split(" ")
def outCommands = new String[commands.length]
for (int i = 0; i < commands.length; i++) {
outCommands[i] = commands[i].replace("~", " ")
}
return Runtime.getRuntime().exec(outCommands, null, f).text.trim()
}
task setChangelog (description: "Sets the changelog to the artifacts") {
doFirst {
def changelog = "https://raw.githubusercontent.com/Dumb-Code/Changelogs/master/dumb_library.txt".toURL().text.trim()
def cftask = tasks.getByName("curseforge$curseforgeID")
//Manually set the changelog, as the changelog in the extension may be cached wrong.
(cftask.property("mainArtifact") as CurseArtifact).changelog = changelog
(cftask.property("additionalArtifacts") as List<CurseArtifact>).forEach {artifact -> artifact.changelog = changelog}
}
}
setChangelog.finalizedBy tasks.getByName("curseforge")
task publishMod (group: "upload", description: "Publish the mod to curseforge and the webhook", dependsOn: setChangelog) {
doLast {
def id = (tasks.getByName("curseforge$curseforgeID").property("mainArtifact") as CurseArtifact).fileID
println "Artifact uploaded with id $id"
def url = "https://www.curseforge.com/minecraft/mc-mods/dumb-library/files/$id"
def datetime = Instant.now().atZone(ZoneOffset.UTC).toString()
def form = new PostForm(dumblibrary_publish_url) //In the ~/.gradle/gradle.properties file
form.addObject new FieldObject('payload_json', "{ \"embeds\": [{ \"title\": \"New Version $project.version !\", \"color\": 6842472, \"url\": \"$url\" , \"timestamp\": \"$datetime\"}]}")
def result = form.send()
println "Webhook uploaded with response code $result.responseCode"
def currentSign = run("git config --global commit.gpgsign", file("."))
//Setup
println run("git clone https://github.com/Dumb-Code/Changelogs.git", file("."))
run "git remote rm origin"
run "git remote add origin https://Travis-CI:${github_token}@github.com/Dumb-Code/Changelogs.git"
//Config
run "git config --global commit.gpgsign false"
println "Successfully cloned and setup git"
//Delete
file("Changelogs/dumb_library.txt").delete()
println "Reset changelog file"
//Push
run "git add dumb_library.txt"
println run("git commit --message \"Deleted~dumb_library.txt~for~new~build\"") //Maybe add version number?
run "git push origin master"
println "Pushed changes to master"
//Re-config
run "git config --global commit.gpgsign $currentSign"
//Delete the folder
FileUtils.deleteDirectory(file("Changelogs"))
println "Cache folder deleted"
}
}
task notifyIfError (group: "upload", description: "Checks to see if travis has errored, and if so sends a webhook") {
doLast {
if(System.getenv("TRAVIS_TEST_RESULT") == "1") {
println "Build has errored. Deploying webhook"
def buildVersion = System.getenv("TRAVIS_BUILD_NUMBER")?: "???"
def url = System.getenv("TRAVIS_BUILD_WEB_URL")?: "???"
def datetime = Instant.now().atZone(ZoneOffset.UTC).toString()
def form = new PostForm(System.getenv('WEBHOOK_URL'))
form.addObject(new FieldObject("payload_json", "{ \"embeds\": [{ \"title\":\"Build $buildVersion has errored - ${System.getenv('TRAVIS_COMMIT_MESSAGE')}\", \"color\": 9306112, \"url\": \"$url\", \"timestamp\":\"$datetime\"}] }"))
def result = form.send()
println "Webhook uploaded with response code $result.responseCode"
}
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
task devJar(type: Jar) {
classifier = "dev"
from sourceSets.main.output
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = "javadoc"
from javadoc.getDestinationDir()
}
artifacts {
archives sourcesJar
archives devJar
archives javadocJar
}
curseforge {
apiKey = project.hasProperty("curseforge_api_key") ? curseforge_api_key : "###"//In the ~/.gradle/gradle.properties file
project {
id = curseforgeID
releaseType = 'beta'
mainArtifact jar
addArtifact sourcesJar
addArtifact devJar
addArtifact javadocJar
}
}
String getDirectVersion() {
if(System.getenv("TRAVIS")) {
return setDebugCommitVersion()
}
def major = "0"
def revision = "0"
def patch = "0"
def prefix = "public static final String VERSION = \""
def file = file("src/main/java/net/dumbcode/dumblibrary/DumbLibrary.java")
file.eachLine { String s ->
s = s.trim()
if (s.startsWith(prefix)) {
s = s.substring(prefix.length(), s.length() - 2)
def pts = s.split("\\.")
if(pts.length != 3) {
return s
}
major = pts[0]
revision = pts[1]
patch = pts[2]
}
}
return "$major.$revision.$patch"
}
processResources {
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
gradlehook {
urlToken System.getenv('WEBHOOK_URL')
addField 'payload_json', '{ "embeds": [{ "title":"' + System.getenv('TRAVIS_COMMIT_MESSAGE') + " - " + System.getenv("COMMITTER_NAME") + '", "timestamp": "{{datetime}}" }] }'
addArtifact jar
}