-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle.kts
286 lines (247 loc) · 10 KB
/
build.gradle.kts
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import nl.javadude.gradle.plugins.license.LicenseExtension
import nl.javadude.gradle.plugins.license.LicensePlugin
import org.ajoberstar.grgit.Grgit
import org.ajoberstar.grgit.operation.DescribeOp
import org.gradle.api.internal.HasConvention
buildscript {
repositories {
maven {
setUrl("https://plugins.gradle.org/m2/")
}
maven {
setUrl("https://ajoberstar.org/bintray-backup/")
}
maven {
setUrl("https://libraries.minecraft.net")
}
}
dependencies {
classpath("gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.13.1")
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
}
}
plugins {
id("org.ajoberstar.grgit") version "4.1.1"
}
group = "io.github.opencubicchunks"
version = getProjectVersion()
val licenseYear = properties["licenseYear"] as String
val projectName = properties["projectName"] as String
val shadowJar: ShadowJar by tasks
val jar: Jar by tasks
apply {
plugin<JavaPlugin>()
plugin<MavenPlugin>()
plugin<SigningPlugin>()
plugin<LicensePlugin>()
plugin<ShadowPlugin>()
}
val sourceSets = the<JavaPluginConvention>().sourceSets!!
configure<JavaPluginConvention> {
setSourceCompatibility(JavaVersion.VERSION_1_8)
}
configure<LicenseExtension> {
val ext = (this as HasConvention).convention.extraProperties
ext["project"] = projectName
ext["year"] = licenseYear
exclude("**/*.info")
exclude("**/package-info.java")
exclude("**/*.json")
exclude("**/*.xml")
exclude("assets/*")
header = file("HEADER.txt")
ignoreFailures = false
strictCheck = true
mapping(mapOf("java" to "SLASHSTAR_STYLE"))
}
repositories {
mavenCentral()
maven {
setUrl("https://oss.sonatype.org/content/groups/public/")
}
maven {
name = "mojang"
setUrl("https://libraries.minecraft.net/")
}
}
dependencies {
compile("com.flowpowered:flow-nbt:1.0.1-SNAPSHOT")
compile("io.github.opencubicchunks:regionlib:0.78.0-SNAPSHOT")
compile("com.carrotsearch:hppc:0.8.1")
compile("com.google.guava:guava:27.0.1-jre")
compile("com.mojang:brigadier:1.0.17")
compile(project(":nbt"))
testCompile("junit:junit:4.11")
}
jar.apply {
manifest.apply {
attributes["Main-Class"] = "cubicchunks.converter.gui.GuiMain"
}
}
/*
val javadocJar by tasks.creating(Jar::class) {
classifier = "javadoc"
from(tasks["javadoc"])
}*/
val sourcesJar by tasks.creating(Jar::class) {
classifier = "sources"
from(sourceSets["main"].java.srcDirs)
}
val headlessJar by tasks.creating(Jar::class) {
classifier = "headless"
from(sourceSets["main"].java.srcDirs)
exclude("cubicchunks/converter/gui")
manifest.apply {
attributes["Main-Class"] = "cubicchunks.converter.headless.HeadlessMain"
}
}
val headlessShadowJar by tasks.creating(ShadowJar::class) {
dependsOn(headlessJar)
manifest.inheritFrom(headlessJar.manifest)
from(java.sourceSets["main"].output)
configurations.add(project.configurations.runtime)
exclude("META-INF/INDEX.LIST", "META-INF/*.SF", "META-INF/*.DSA", "META-INF/*.RSA", "cubicchunks/converter/gui")
classifier = "headless-all"
}
tasks["build"].dependsOn(shadowJar, headlessShadowJar)
val signing: SigningExtension by extensions
signing.apply {
isRequired = false
// isRequired = gradle.taskGraph.hasTask("uploadArchives")
sign(configurations.archives)
}
// based on:
// https://github.com/Ordinastie/MalisisCore/blob/30d8efcfd047ac9e9bc75dfb76642bd5977f0305/build.gradle#L204-L256
// https://github.com/gradle/kotlin-dsl/blob/201534f53d93660c273e09f768557220d33810a9/samples/maven-plugin/build.gradle.kts#L10-L44
val uploadArchives: Upload by tasks
uploadArchives.apply {
repositories {
withConvention(MavenRepositoryHandlerConvention::class) {
mavenDeployer {
// Sign Maven POM
beforeDeployment {
signing.signPom(this)
}
val username = if (project.hasProperty("sonatypeUsername")) project.properties["sonatypeUsername"] else System.getenv("sonatypeUsername")
val password = if (project.hasProperty("sonatypePassword")) project.properties["sonatypePassword"] else System.getenv("sonatypePassword")
withGroovyBuilder {
"snapshotRepository"("url" to "https://oss.sonatype.org/content/repositories/snapshots") {
"authentication"("userName" to username, "password" to password)
}
"repository"("url" to "https://oss.sonatype.org/service/local/staging/deploy/maven2") {
"authentication"("userName" to username, "password" to password)
}
}
// Maven POM generation
pom.project {
withGroovyBuilder {
"name"(projectName)
"artifactId"(base.archivesBaseName.toLowerCase())
"packaging"("jar")
"url"("https://github.com/OpenCubicChunks/CubicChunksConverter")
"description"("Save converter from vanilla Minecraft to cubic chunks")
"scm" {
"connection"("scm:git:git://github.com/OpenCubicChunks/CubicChunksConverter.git")
"developerConnection"("scm:git:ssh://[email protected]:OpenCubicChunks/CubicChunksConverter.git")
"url"("https://github.com/OpenCubicChunks/CubicChunksConverter")
}
"licenses" {
"license" {
"name"("The MIT License")
"url"("http://www.tldrlegal.com/license/mit-license")
"distribution"("repo")
}
}
"developers" {
"developer" {
"id"("Barteks2x")
"name"("Barteks2x")
}
}
"issueManagement" {
"system"("github")
"url"("https://github.com/OpenCubicChunks/CubicChunksConverter/issues")
}
}
}
}
}
}
}
// tasks must be before artifacts, don't change the order
artifacts {
withGroovyBuilder {
"archives"(jar, shadowJar, headlessJar, headlessShadowJar, sourcesJar)
}
}
//returns version string according to this: http://semver.org/
//format: MAJOR.MINOR.PATCH
fun getProjectVersion(): String {
try {
val git = Grgit.open()
val describeOp = DescribeOp(git.repository)
describeOp.tags = false
val describe = describeOp.call()
val branch = getGitBranch(git)
val snapshotSuffix = if (project.hasProperty("doRelease")) "" else "-SNAPSHOT"
return getVersion_do(describe, branch) + snapshotSuffix
} catch (ex: RuntimeException) {
logger.error("Unknown error when accessing git repository! Are you sure the git repository exists?", ex)
return String.format("v9999-9999-gffffff", "localbuild")
}
}
fun getGitBranch(git: Grgit): String {
var branch: String = git.branch.current.name
if (branch.equals("HEAD")) {
branch = when {
System.getenv("TRAVIS_BRANCH")?.isEmpty() == false -> // travis
System.getenv("TRAVIS_BRANCH")
System.getenv("GIT_BRANCH")?.isEmpty() == false -> // jenkins
System.getenv("GIT_BRANCH")
System.getenv("BRANCH_NAME")?.isEmpty() == false -> // ??? another jenkins alternative?
System.getenv("BRANCH_NAME")
else -> throw RuntimeException("Found HEAD branch! This is most likely caused by detached head state! Will assume unknown version!")
}
}
if (branch.startsWith("origin/")) {
branch = branch.substring("origin/".length)
}
return branch
}
fun getVersion_do(describe: String, branch: String): String {
val versionMinorFreeze = project.property("versionMinorFreeze") as String
//branch "master" is not appended to version string, everything else is
//only builds from "master" branch will actually use the correct versioning
//but it allows to distinguish between builds from different branches even if version number is the same
val branchSuffix = if (branch == "master") "" else ("-" + branch.replace("[^a-zA-Z0-9.-]", "_"))
val baseVersionRegex = "v[0-9]+"
val unknownVersion = String.format("UNKNOWN_VERSION%s", branchSuffix)
if (!describe.contains('-')) {
//is it the "vX" format?
if (describe.matches(Regex(baseVersionRegex))) {
return String.format("%s.0.0%s", describe, branchSuffix)
}
logger.error("Git describe information: \"$describe\" in unknown/incorrect format")
return unknownVersion
}
//Describe format: vX-build-hash
val parts = describe.split("-")
if (!parts[0].matches(Regex(baseVersionRegex))) {
logger.error("Git describe information: \"$describe\" in unknown/incorrect format")
return unknownVersion
}
if (!parts[1].matches(Regex("[0-9]+"))) {
logger.error("Git describe information: \"$describe\" in unknown/incorrect format")
return unknownVersion
}
val apiVersion = parts[0].substring(1)
//next we have commit-since-tag
val commitSinceTag = Integer.parseInt(parts[1])
val minorFreeze = if (versionMinorFreeze.isEmpty()) -1 else Integer.parseInt(versionMinorFreeze)
val minor = if (minorFreeze < 0) commitSinceTag else minorFreeze
val patch = if (minorFreeze < 0) 0 else (commitSinceTag - minorFreeze)
val version = String.format("%s.%d.%d%s", apiVersion, minor, patch, branchSuffix)
return version
}