-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.gradle
263 lines (230 loc) · 6.69 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
def corePlugin = ''
buildscript {
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'
classpath 'gradle.plugin.com.matthewprenger:CurseGradle:1.4.0'
classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.0'
}
}
apply plugin: 'net.minecraftforge.gradle.forge'
apply plugin: 'com.matthewprenger.cursegradle'
apply plugin: 'maven-publish'
apply plugin: 'org.sonarqube'
javadoc {
failOnError = false
}
description = 'Additional Loot Tables'
def mod_file = getModFile()
def mc_version = '1.12'
ext {
short_version = getVersion('VERSION', mod_file)
}
version = mc_version + '-' + short_version
if (System.getenv().BUILD_NUMBER) {
version += '.' + System.getenv().BUILD_NUMBER
}
group = 'com.mcmoddev'
sourceCompatibility = targetCompatibility = '1.8'
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
}
}
minecraft {
version = '1.12.2-14.23.4.2705'
runDir = 'run'
mappings = 'stable_39'
replace '@FINGERPRINT@', project.findProperty('signSHA1')
}
repositories {
maven {
name 'MMD'
url 'https://maven.mcmoddev.com/'
}
}
dependencies {
// None
}
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'
}
}
jar {
manifest {
}
}
task apiJar(type: Jar) {
classifier = 'apiClasses'
from apiClasses
}
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
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.getDestinationDir()
}
artifacts {
// archives apiJar
archives deobfJar
archives sourceJar
archives javadocJar
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId project.group
artifactId project.archivesBaseName
version project.version
from components.java
artifact sourceJar {
classifier 'sources'
}
artifact apiJar {
classifier 'api'
}
artifact deobfJar {
classifier 'deobf'
}
artifact javadocJar {
classifier 'javadoc'
}
}
}
repositories {
maven {
credentials {
username secret.username
password secret.password
}
url secret.url
}
}
}
curseforge {
apiKey = secret.curseforgeAPIKey
project {
id = '243157'
changelog = file('CHANGELOG.txt')
releaseType = 'release'
addGameVersion(project.mc_version)
def projectName = 'Additional Loot Tables'
def displayVersion = getVersion('VERSION', mod_file)
if (System.getenv().BUILD_NUMBER) {
displayVersion += '.' + System.getenv().BUILD_NUMBER
}
mainArtifact(jar) {
displayName = "$project.description $displayVersion"
// relations {
// }
}
// addArtifact(apiJar) {
// displayName = "$project.description $displayVersion API"
// }
addArtifact(sourceJar) {
displayName = "$project.description $displayVersion Sources"
}
addArtifact(deobfJar) {
displayName = "$project.description $displayVersion Development"
}
addArtifact(javadocJar) {
displayName = "$project.description $displayVersion Javadoc"
}
}
}
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'
String prefix = "public static final String $type = \""
File file = file(mod_file)
file.eachLine { String s ->
s = s.trim()
if (s.startsWith(prefix)) {
s = s.substring(prefix.length(), s.length() - 2)
String[] pts = s.split("\\.")
major = pts[0]
revision = pts[1]
patch = pts[2]
}
}
return "$major.$revision.$patch"
}