|
1 |
| -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 1 | +import org.yaml.snakeyaml.DumperOptions |
| 2 | +import org.yaml.snakeyaml.Yaml |
2 | 3 | import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
|
3 |
| -import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig |
4 | 4 | import java.time.OffsetDateTime
|
5 | 5 | import java.time.ZoneOffset
|
6 | 6 | import java.time.format.DateTimeFormatter
|
7 | 7 |
|
8 | 8 | plugins {
|
9 |
| - kotlin("jvm") version "1.6.10" |
10 |
| - id("com.github.johnrengelman.shadow") version "7.1.2" |
11 |
| - id("pl.allegro.tech.build.axion-release") version "1.13.6" |
12 |
| - id("org.jlleitschuh.gradle.ktlint") version "10.2.1" |
| 9 | + alias(libs.plugins.axionRelease) |
| 10 | + alias(libs.plugins.kotlin) |
| 11 | + alias(libs.plugins.ktlint) |
| 12 | + alias(libs.plugins.shadow) |
13 | 13 | }
|
14 | 14 |
|
15 |
| -val repoRef = "SimpleMC\\/SimpleNPCs" |
16 |
| -val mcApiVersion = "1.18" |
17 |
| - |
18 |
| -group = "org.simplemc" |
19 |
| -version = scmVersion.version |
20 |
| - |
21 | 15 | scmVersion {
|
22 | 16 | versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
|
| 17 | + unshallowRepoOnCI.set(true) |
| 18 | + |
| 19 | + hooks { |
| 20 | + // Automate moving `[Unreleased]` changelog entries into `[<version>]` on release |
| 21 | + // FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500 |
| 22 | + val changelogPattern = |
| 23 | + "\\[Unreleased\\]([\\s\\S]+?)\\n" + |
| 24 | + "(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/(\\S+\\/\\S+)\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" |
| 25 | + pre( |
| 26 | + "fileUpdate", |
| 27 | + mapOf( |
| 28 | + "file" to "CHANGELOG.md", |
| 29 | + "pattern" to KotlinClosure2<String, HookContext, String>({ _, _ -> changelogPattern }), |
| 30 | + "replacement" to KotlinClosure2<String, HookContext, String>({ version, context -> |
| 31 | + // github "diff" for previous version |
| 32 | + val previousVersionDiffLink = |
| 33 | + when (context.previousVersion == version) { |
| 34 | + true -> "releases/tag/v$version" // no previous, just link to the version |
| 35 | + false -> "compare/v${context.previousVersion}...v$version" |
| 36 | + } |
| 37 | + """ |
| 38 | + \[Unreleased\] |
| 39 | +
|
| 40 | + ## \[$version\] - $currentDateString$1 |
| 41 | + \[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD |
| 42 | + \[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3 |
| 43 | + """.trimIndent() |
| 44 | + }), |
| 45 | + ), |
| 46 | + ) |
23 | 47 |
|
24 |
| - hooks( |
25 |
| - closureOf<HooksConfig> { |
26 |
| - // "normal" changelog update--changelog already contains a history |
27 |
| - pre( |
28 |
| - "fileUpdate", |
29 |
| - mapOf( |
30 |
| - "file" to "CHANGELOG.md", |
31 |
| - "pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> |
32 |
| - "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/release-$v\\.\\.\\.HEAD\$([\\s\\S]*))?\\z" |
33 |
| - }), |
34 |
| - "replacement" to KotlinClosure2<String, HookContext, String>({ v, c -> |
35 |
| - """ |
36 |
| - \[Unreleased\] |
37 |
| - |
38 |
| - ## \[$v\] - ${currentDateString()}$1 |
39 |
| - \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD |
40 |
| - \[$v\]: https:\/\/github\.com\/$repoRef\/compare\/release-${c.previousVersion}...release-$v$2 |
41 |
| - """.trimIndent() |
42 |
| - }) |
43 |
| - ) |
44 |
| - ) |
45 |
| - // first-time changelog update--changelog has only unreleased info |
46 |
| - pre( |
47 |
| - "fileUpdate", |
48 |
| - mapOf( |
49 |
| - "file" to "CHANGELOG.md", |
50 |
| - "pattern" to KotlinClosure2<String, HookContext, String>({ _, _ -> |
51 |
| - "Unreleased([\\s\\S]+?\\nand this project adheres to \\[Semantic Versioning\\]\\(https:\\/\\/semver\\.org\\/spec\\/v2\\.0\\.0\\.html\\).)\\s\\z" |
52 |
| - }), |
53 |
| - "replacement" to KotlinClosure2<String, HookContext, String>({ v, _ -> |
54 |
| - """ |
55 |
| - \[Unreleased\] |
56 |
| - |
57 |
| - ## \[$v\] - ${currentDateString()}$1 |
58 |
| - |
59 |
| - \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD |
60 |
| - \[$v\]: https:\/\/github\.com\/$repoRef\/releases\/tag\/release-$v |
61 |
| - """.trimIndent() |
62 |
| - }) |
63 |
| - ) |
64 |
| - ) |
65 |
| - pre("commit") |
66 |
| - } |
67 |
| - ) |
| 48 | + pre("commit") |
| 49 | + } |
68 | 50 | }
|
69 | 51 |
|
70 |
| -fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) |
| 52 | +group = "org.simplemc" |
| 53 | +version = scmVersion.version |
71 | 54 |
|
72 |
| -java { |
73 |
| - toolchain { |
74 |
| - languageVersion.set(JavaLanguageVersion.of(17)) |
75 |
| - } |
76 |
| -} |
| 55 | +val currentDateString: String |
| 56 | + get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) |
77 | 57 |
|
78 |
| -repositories { |
79 |
| - mavenCentral() |
80 |
| - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") |
81 |
| - maven("https://oss.sonatype.org/content/repositories/snapshots") |
| 58 | +kotlin { |
| 59 | + jvmToolchain(21) |
82 | 60 | }
|
83 | 61 |
|
84 | 62 | dependencies {
|
85 |
| - implementation(kotlin("stdlib-jdk8")) |
86 |
| - compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+") |
| 63 | + compileOnly(libs.spigot) |
87 | 64 | }
|
88 | 65 |
|
89 | 66 | tasks {
|
90 | 67 | wrapper {
|
91 |
| - gradleVersion = "7.4.1" |
92 | 68 | distributionType = Wrapper.DistributionType.ALL
|
93 | 69 | }
|
94 | 70 |
|
95 | 71 | processResources {
|
96 | 72 | val placeholders = mapOf(
|
97 | 73 | "version" to version,
|
98 |
| - "apiVersion" to mcApiVersion |
| 74 | + "apiVersion" to libs.versions.mcApi.get(), |
| 75 | + "kotlinVersion" to libs.versions.kotlin.get(), |
99 | 76 | )
|
100 | 77 |
|
101 | 78 | filesMatching("plugin.yml") {
|
102 | 79 | expand(placeholders)
|
103 | 80 | }
|
| 81 | + |
| 82 | + // create an "offline" copy/variant of the plugin.yml with `libraries` omitted |
| 83 | + doLast { |
| 84 | + val resourcesDir = sourceSets.main.get().output.resourcesDir |
| 85 | + val yamlDumpOptions = |
| 86 | + // make it pretty for the people |
| 87 | + DumperOptions().also { |
| 88 | + it.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK |
| 89 | + it.isPrettyFlow = true |
| 90 | + } |
| 91 | + val yaml = Yaml(yamlDumpOptions) |
| 92 | + val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream()) |
| 93 | + yaml.dump(pluginYml.filterKeys { it != "libraries" }, file("$resourcesDir/offline-plugin.yml").writer()) |
| 94 | + } |
104 | 95 | }
|
105 | 96 |
|
106 |
| - // standard jar should be ready to go with all dependencies |
107 |
| - shadowJar { |
108 |
| - minimize() |
109 |
| - archiveClassifier.set("") |
| 97 | + jar { |
| 98 | + exclude("offline-plugin.yml") |
110 | 99 | }
|
111 | 100 |
|
112 |
| - // nokt jar without the kotlin runtime |
113 |
| - register<ShadowJar>("nokt") { |
| 101 | + // offline jar should be ready to go with all dependencies |
| 102 | + shadowJar { |
114 | 103 | minimize()
|
115 |
| - archiveClassifier.set("nokt") |
116 |
| - from(sourceSets.main.get().output) |
117 |
| - configurations = listOf(project.configurations.runtimeClasspath.get()) |
118 |
| - |
119 |
| - dependencies { |
120 |
| - exclude(dependency("org.jetbrains.*:")) |
121 |
| - } |
122 |
| - } |
| 104 | + archiveClassifier.set("offline") |
| 105 | + exclude("plugin.yml") |
| 106 | + rename("offline-plugin.yml", "plugin.yml") |
123 | 107 |
|
124 |
| - build { |
125 |
| - dependsOn(":shadowJar", ":nokt") |
| 108 | + // avoid classpath conflicts/pollution via relocation |
| 109 | + isEnableRelocation = true |
| 110 | + relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries" |
126 | 111 | }
|
127 | 112 | }
|
0 commit comments