forked from spnda/BlockProt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle.kts
108 lines (90 loc) · 3.06 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
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
buildscript {
repositories {
maven("https://plugins.gradle.org/m2/")
}
dependencies {
classpath("org.kohsuke:github-api:1.314")
}
}
plugins {
id("org.gradle.java-library")
id("org.ajoberstar.grgit") version "5.2.0"
id("org.cadixdev.licenser") version "0.6.1"
}
fun gitBranchName(): String {
val env = System.getenv()
if (env["GITHUB_REF"] != null) {
val branch = env["GITHUB_REF"]!!
return branch.substring(branch.lastIndexOf("/") + 1)
}
val branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
val env: MutableMap<String, String> = System.getenv()
val blockProtVersion: String by project
allprojects {
apply(plugin = "org.gradle.java-library")
apply(plugin = "org.cadixdev.licenser")
group = "de.sean.blockprot"
version = blockProtVersion
repositories {
mavenLocal()
maven("https://jitpack.io") {
name = "JitPack"
}
mavenCentral()
}
tasks.compileJava {
options.release.set(16)
java.sourceCompatibility = JavaVersion.VERSION_16
java.targetCompatibility = JavaVersion.VERSION_16
}
ext["gitBranchName"] = gitBranchName()
tasks.jar {
// The default configuration for the archivesName is
// [baseName]-[appendix]-[version]-[classifier].[extension]
archiveClassifier.set(
if (ext["gitBranchName"] == "master" || ext["gitBranchName"] == "HEAD") null
else (ext["gitBranchName"] as String))
}
afterEvaluate {
// We use license instead of spotless now, as spotless'
// java formatter had too many issues.
license {
header(rootProject.file("HEADER.txt"))
include("**/*.java")
properties {
this["year"] = "2021 - 2023"
}
}
}
}
tasks.register("github") {
onlyIf {
env["GITHUB_TOKEN"] != null
}
doLast {
val github = GitHub.connectUsingOAuth(env["GITHUB_TOKEN"] as String)
val repository = github.getRepository(env["GITHUB_REPOSITORY"])
val releaseBuilder = GHReleaseBuilder(repository, version as String)
releaseBuilder.name(version as String)
releaseBuilder.body(env["CHANGELOG"] ?: "No changelog.")
releaseBuilder.commitish(gitBranchName())
// Get the output JARs for each subproject.
val files = mutableListOf<File?>()
subprojects.filter { it.name != "common" }.forEach {
val dir = "${it.buildDir}/libs/"
files.add(file(dir).listFiles()?.last { file ->
file.nameWithoutExtension.endsWith("all")
})
}
val ghRelease = releaseBuilder.create()
files.forEach {
ghRelease.uploadAsset(it, "application/java-archive")
}
// We set the proper name here, as "releaseBuilder.name" is also used for the tag name.
ghRelease.update().name("BlockProt $version").update()
}
}