|
1 | | -import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation |
2 | 1 | import org.yaml.snakeyaml.DumperOptions |
3 | 2 | import org.yaml.snakeyaml.Yaml |
4 | 3 | import pl.allegro.tech.build.axion.release.domain.hooks.HookContext |
5 | 4 | import java.time.OffsetDateTime |
6 | 5 | import java.time.ZoneOffset |
7 | 6 | import java.time.format.DateTimeFormatter |
8 | 7 |
|
9 | | -buildscript { |
10 | | - repositories { |
11 | | - mavenCentral() |
12 | | - } |
13 | | - dependencies { |
14 | | - classpath("org.yaml:snakeyaml:2.0") |
15 | | - } |
16 | | -} |
17 | | - |
18 | 8 | plugins { |
19 | | - kotlin("jvm") |
20 | | - id("com.github.johnrengelman.shadow") version "8.0.0" |
21 | | - id("pl.allegro.tech.build.axion-release") version "1.14.4" |
22 | | - id("org.jlleitschuh.gradle.ktlint") version "11.2.0" |
| 9 | + alias(libs.plugins.axionRelease) |
| 10 | + alias(libs.plugins.kotlin) |
| 11 | + alias(libs.plugins.ktlint) |
| 12 | + alias(libs.plugins.shadow) |
23 | 13 | } |
24 | 14 |
|
25 | | -group = "org.simplemc" |
26 | | -version = scmVersion.version |
27 | | - |
28 | | -val mcApiVersion: String by project |
29 | | -val repoRef: String by project |
30 | | - |
31 | 15 | scmVersion { |
32 | 16 | versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+")) |
| 17 | + unshallowRepoOnCI.set(true) |
33 | 18 |
|
34 | 19 | hooks { |
| 20 | + // Automate moving `[Unreleased]` changelog entries into `[<version>]` on release |
35 | 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" |
36 | 25 | pre( |
37 | 26 | "fileUpdate", |
38 | 27 | mapOf( |
39 | 28 | "file" to "CHANGELOG.md", |
40 | | - "pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> |
41 | | - "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z" |
42 | | - }), |
43 | | - "replacement" to KotlinClosure2<String, HookContext, String>({ v, c -> |
| 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 | + } |
44 | 37 | """ |
45 | 38 | \[Unreleased\] |
46 | 39 |
|
47 | | - ## \[$v\] - ${currentDateString()}$1 |
48 | | - \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD |
49 | | - \[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2 |
| 40 | + ## \[$version\] - $currentDateString$1 |
| 41 | + \[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD |
| 42 | + \[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3 |
50 | 43 | """.trimIndent() |
51 | | - }) |
52 | | - ) |
| 44 | + }), |
| 45 | + ), |
53 | 46 | ) |
54 | 47 |
|
55 | 48 | pre("commit") |
56 | 49 | } |
57 | 50 | } |
58 | 51 |
|
59 | | -fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) |
| 52 | +group = "org.simplemc" |
| 53 | +version = scmVersion.version |
60 | 54 |
|
61 | | -java { |
62 | | - toolchain { |
63 | | - languageVersion.set(JavaLanguageVersion.of(17)) |
64 | | - } |
65 | | -} |
| 55 | +val currentDateString: String |
| 56 | + get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) |
66 | 57 |
|
67 | | -repositories { |
68 | | - mavenCentral() |
69 | | - maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") |
70 | | - maven("https://oss.sonatype.org/content/repositories/snapshots") |
| 58 | +kotlin { |
| 59 | + jvmToolchain(21) |
71 | 60 | } |
72 | 61 |
|
73 | 62 | dependencies { |
74 | | - implementation(kotlin("stdlib-jdk8")) |
75 | | - compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+") |
| 63 | + compileOnly(libs.spigot) |
76 | 64 | } |
77 | 65 |
|
78 | 66 | tasks { |
79 | 67 | wrapper { |
80 | | - gradleVersion = "8.0.1" |
81 | 68 | distributionType = Wrapper.DistributionType.ALL |
82 | 69 | } |
83 | 70 |
|
84 | 71 | processResources { |
85 | 72 | val placeholders = mapOf( |
86 | 73 | "version" to version, |
87 | | - "apiVersion" to mcApiVersion, |
88 | | - "kotlinVersion" to project.properties["kotlinVersion"] |
| 74 | + "apiVersion" to libs.versions.mcApi.get(), |
| 75 | + "kotlinVersion" to libs.versions.kotlin.get(), |
89 | 76 | ) |
90 | 77 |
|
91 | 78 | filesMatching("plugin.yml") { |
@@ -117,15 +104,9 @@ tasks { |
117 | 104 | archiveClassifier.set("offline") |
118 | 105 | exclude("plugin.yml") |
119 | 106 | rename("offline-plugin.yml", "plugin.yml") |
120 | | - } |
121 | | - |
122 | | - // avoid classpath conflicts/pollution via relocation |
123 | | - val configureShadowRelocation by registering(ConfigureShadowRelocation::class) { |
124 | | - target = shadowJar.get() |
125 | | - prefix = "${project.group}.${project.name.lowercase()}.libraries" |
126 | | - } |
127 | 107 |
|
128 | | - build { |
129 | | - dependsOn(shadowJar).dependsOn(configureShadowRelocation) |
| 108 | + // avoid classpath conflicts/pollution via relocation |
| 109 | + isEnableRelocation = true |
| 110 | + relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries" |
130 | 111 | } |
131 | 112 | } |
0 commit comments