forked from chunky-dev/chunky
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
241 lines (201 loc) · 6.38 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
project.version = getVersion()
println "Building version ${project.version}"
allprojects {
repositories {
mavenCentral()
mavenLocal()
}
}
buildscript {
repositories {
maven {
setUrl("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath 'org.openjfx:javafx-plugin:0.0.13'
classpath 'com.github.ben-manes:gradle-versions-plugin:0.46.0'
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.openjfx.javafxplugin'
apply plugin: 'idea'
apply plugin: 'com.github.ben-manes.versions'
group = 'se.llbit'
version = rootProject.version
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
compileJava {
options.encoding = 'UTF-8'
options.debug = true
options.deprecation = true
}
javafx {
version = '11.0.2'
configuration = 'implementation'
modules = ['javafx.base', 'javafx.controls', 'javafx.fxml']
}
javadoc {
options.encoding = 'UTF-8'
options.addStringOption('Xdoclint:none', '-quiet')
}
configurations {
jsonlib
nbtlib
cplib
toolpanelib
}
dependencies {
jsonlib 'se.llbit:jo-json:1.3.1'
nbtlib 'se.llbit:jo-nbt:1.3.0'
cplib 'se.llbit:luxcp:1.0.1'
toolpanelib 'se.llbit:toolpane:0.1'
}
idea {
module {
downloadJavadoc = true
downloadSources = true
}
}
dependencyUpdates.gradleReleaseChannel = "current"
tasks.named("dependencyUpdates") {
def isNonStable = { String version ->
def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { keyword -> version.toUpperCase().contains(keyword) }
def regex = /^[0-9,.v-]+(-r)?$/
return !stableKeyword && !(version ==~ regex)
}
rejectVersionIf {
isNonStable(it.candidate.version)
}
}
}
defaultTasks 'release'
task releaseVersion {
doLast {
tryCommand([ 'git', 'tag', '-a', "${project.version}", '-m', "Version ${project.version}" ], true)
}
}
task versionInfo(type: JavaExec) {
dependsOn 'copyArtifacts'
outputs.upToDateWhen { false }
outputs.files file("build/chunky-${project.version}.jar")
description 'Writes build/chunky-VERSION.jar, latest.json and updates chunky-core-VERSION.jar/version.json'
classpath = project(':releasetools').sourceSets.main.runtimeClasspath
mainClass.set('releasetools.ReleaseBuilder')
args "${project.version}", "release_notes-${project.version}.txt"
}
task release {
dependsOn 'buildReleaseJar', 'versionInfo'
def destinationDirectory = file("${buildDir}/release")
doLast {
project.delete(destinationDirectory)
destinationDirectory.mkdirs()
file("./latest.json").renameTo("${destinationDirectory}/latest.json")
fileTree(buildDir).matching {
include "*-${project.version}.*"
}.each {
it.renameTo("${destinationDirectory}/${it.name}")
}
}
}
task buildReleaseJar(type: Jar) {
dependsOn 'versionInfo'
archiveFileName = "chunky-${project.version}.jar"
destinationDirectory = file('build/installer')
manifest {
attributes('Main-Class': 'se.llbit.chunky.launcher.ChunkyLauncher')
}
into('lib') {
from fileTree('chunky/lib').include('*.jar')
from file("build/chunky-core-${project.version}.jar")
}
from {
project(':launcher').configurations.archives.allArtifacts.files.collect {
zipTree(it)
}
}
from file("./latest.json")
rename "latest.json", "version.json"
}
task copyArtifacts(type: Copy) {
dependsOn subprojects.jar
from subprojects.jar
into buildDir
}
/** Helper function to run a command. Returns the command output if the command succeeded. */
def tryCommand(def command, boolean failOnError = false) {
def out = new StringBuilder()
def err = new StringBuilder()
try {
def proc = command.execute()
proc.waitForProcessOutput(out, err)
if (proc.exitValue()) {
def msg = "failed to run '${command[0]}' (args: ${command.tail()})\n$err$out"
if (failOnError) {
throw new GradleException(msg)
} else {
print 'Warning: '
println msg
}
""
} else {
if (err) println "${err}"
out.toString()
}
} catch (IOException e) {
println "failed to run ${command[0]} (args: ${command.tail()}): $e"
""
}
}
/** Helper function to retrieve the current version string. */
def getVersion() {
if (project.hasProperty('newVersion')) {
// Manual version override
return project.newVersion
}
// Prerelease version based on stored version and git history
def prerelease = "DEV"
if (project.hasProperty('prereleaseTag')) {
prerelease = project.prereleaseTag
}
// Get the stored major version
Properties versionProperties = new Properties()
versionProperties.load(new FileInputStream(file('chunky/src/res/se/llbit/chunky/main/Version.properties')))
def majorVersion = versionProperties['version']
def preVersion = "0";
// Attempt to get Git describe output
def gitDescribe = tryCommand(['git', 'describe', '--abbrev=7', '--long'])
if (gitDescribe) {
def gitMatcher = gitDescribe =~ /^.*?-(\d*)-(g.*)/
gitMatcher.find()
if (gitMatcher.groupCount() >= 2) {
preVersion = gitMatcher.group(1) + "." + gitMatcher.group(2)
}
}
return majorVersion + "-" + prerelease + "." + preVersion
}
task install(dependsOn: ':chunky:publish') {
doLast {
copy {
from file("${project(':chunky').buildDir}/maven/")
into file("${buildDir}/maven/")
}
project.delete(file("${project(':chunky').buildDir}/maven/"))
}
}
// Includes both main and library documentation:
task docs(type: Javadoc) {
options.encoding = 'UTF-8'
options.addStringOption('Xdoclint:none', '-quiet')
def docProjects = [ ':chunky', ':lib' ]
source docProjects.collect { project(it).sourceSets.main.allJava }
classpath = files(docProjects.collect { project(it).sourceSets.main.compileClasspath })
destinationDir = file("${buildDir}/docs/javadoc")
}
task clean {
doLast {
delete "./build"
}
}