-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
272 lines (234 loc) · 6.39 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
263
264
265
266
267
268
269
270
271
272
buildscript {
repositories {
//jcenter()
maven {
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
maven {
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
name = 'forge'
url = 'http://files.minecraftforge.net/maven'
}
maven {
name = 'gradle'
url 'https://plugins.gradle.org/m2/'
}
maven {
name = 'sonatype'
url = 'https://oss.sonatype.org/content/groups/public'
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
plugins {
id "com.matthewprenger.cursegradle" version "1.2.0"
id "org.sonarqube" version "2.6.2"
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.matthewprenger.cursegradle'
apply plugin: 'maven-publish'
apply plugin: 'org.sonarqube'
repositories {
mavenLocal()
mavenCentral()
}
minecraft {
version = "1.12.2-14.23.5.2823"
runDir = "run"
mappings = "stable_39"
replace '@FINGERPRINT@', project.findProperty('signSHA1')
if (project.hasProperty('mc_username')) {
clientRunArgs += ['--username', "${project.mc_username}"]
if (project.hasProperty('mc_password')) {
clientRunArgs += ['--password=', "${project.mc_password}"]
}
}
if (project.hasProperty('mc_uuid')) {
clientRunArgs += ['--uuid', "${project.mc_uuid}"]
}
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
javadoc {
failOnError = false
}
def mod_file = getModFile()
def short_version = getVersion('VERSION', mod_file)
version = mc_version + '-' + short_version
def display_version = short_version
if (System.getenv().BUILD_NUMBER) {
version += '.' + System.getenv().BUILD_NUMBER
display_version = '.' + System.getenv().BUILD_NUMBER
}
sourceCompatibility = targetCompatibility = '1.8'
eclipse.project {
buildCommand 'org.eclipse.buildship.core.gradleprojectbuilder'
natures 'org.eclipse.buildship.core.gradleprojectnature'
}
class Secrets {
def data = null
def getProperty(String key) {
return data ? data[key] : ''
}
}
import groovy.json.JsonSlurper
def secretFile
if (System.getenv().SECRET_FILE) {
secretFile = file System.getenv().SECRET_FILE
} else {
secretFile = file 'secret.json'
}
project.ext.secret = new Secrets()
if (secretFile.exists()) {
secretFile.withReader {
project.ext.secret.data = new JsonSlurper().parse it
}
}
repositories {
maven {
name = 'CurseForge'
url = 'https://minecraft.curseforge.com/api/maven/'
}
maven {
name = 'rogwml6 maven'
url = 'http://dvs1.progwml6.com/files/maven'
}
}
dependencies {
deobfCompile 'jei:jei_1.12.2:4.15.0.268'
}
processResources {
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
from (sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': short_version, 'mcversion': project.minecraft.version
}
from (sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
rename '(.+_at.cfg)', 'META-INF/$1'
}
jar {
manifest {
if (project.hasProperty('coreplugin')) {
attributes 'FMLCorePluginContainsFMLMod': 'true'
attributes 'FMLCorePlugin': project.coreplugin
}
}
}
task deobfJar(type: Jar) {
classifier = 'deobf'
from sourceSets.main.output
}
task signJar(type: SignJar, dependsOn: reobfJar) {
// Skips if the keyStore property is missing.
onlyIf {
project.hasProperty('keyStore')
}
// findProperty allows us to reference the property without it existing.
// Using project.propName would cause the script to fail validation if
// the property did not exist.
keyStore = project.findProperty('keyStore')
alias = project.findProperty('keyStoreAlias')
storePass = project.findProperty('keyStorePass')
keyPass = project.findProperty('keyStoreKeyPass')
inputFile = jar.archivePath
outputFile = jar.archivePath
}
build.dependsOn signJar
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
from components.java
artifact sourceJar {
classifier 'sources'
}
}
}
repositories {
maven {
credentials {
username secret.username
password secret.password
}
url secret.url
}
}
}
processResources {
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
from (sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand 'version': short_version, 'mcversion': project.minecraft.version
}
from (sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
}
curseforge {
if (project.hasProperty('cf_project_id') && project.hasProperty('cf_release_type') &&
((project.cf_release_type == "alpha") || (project.cf_release_type == "beta") || (project.cf_release_type == "release"))) {
apiKey = secret.curseforgeAPIKey
project {
id = project.cf_project_id
changelog = file('CHANGELOG.txt')
releaseType = project.cf_release_type
addGameVersion(project.mc_version)
}
}
}
sonarqube {
properties {
property 'sonar.host.url', secret.sonarHost
property 'sonar.organization', secret.sonarOrganization
property 'sonar.login', secret.sonarToken
property 'sonar.projectName', project.archivesBaseName
property 'sonar.projectKey', "$project.group:$project.archivesBaseName"
}
}
String getModFile() {
String path = ''
FileTree tree = fileTree(dir: 'src/main/java')
tree.include '**/*.java'
tree.visit { element ->
if (element.file.isFile()) {
element.file.eachLine { String s ->
s = s.trim()
if (s.startsWith('@Mod(')) {
path = "src/main/java/$element.relativePath"
}
}
}
}
return path
}
String getVersion(String type, String mod_file) {
String major = '0'
String revision = '0'
String patch = '0'
File file = file(mod_file)
def prefix = ~/^(?:public|protected|private) static final String $type = ".*$/
file.eachLine { String s ->
s = s.trim()
if (s ==~ prefix || prefix.matcher(s).matches()) {
String[] bits = s.split("=")
String interesting = bits[1].trim()
interesting = interesting.substring(1, interesting.length() - 2)
String[] pts = interesting.trim().split("\\.")
major = pts[0] ?: '0'
revision = pts[1] ?: '0'
patch = pts[2] ?: '0'
}
}
return "$major.$revision.$patch"
}