|
| 1 | +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar |
| 2 | +import pl.allegro.tech.build.axion.release.domain.hooks.HookContext |
| 3 | +import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig |
| 4 | +import java.time.OffsetDateTime |
| 5 | +import java.time.ZoneOffset |
| 6 | +import java.time.format.DateTimeFormatter |
| 7 | + |
| 8 | +plugins { |
| 9 | + kotlin("jvm") version "1.3.61" |
| 10 | + id("com.github.johnrengelman.shadow") version "5.2.0" |
| 11 | + id("pl.allegro.tech.build.axion-release") version "1.10.3" |
| 12 | + id("org.jlleitschuh.gradle.ktlint") version "9.1.1" |
| 13 | +} |
| 14 | + |
| 15 | +val repoRef = "SimpleMC\\/mc-kotlin-plugin-template" |
| 16 | +val mcApiVersion = "1.15" |
| 17 | + |
| 18 | +group = "org.simplemc" |
| 19 | +version = scmVersion.version |
| 20 | + |
| 21 | +scmVersion { |
| 22 | + hooks(closureOf<HooksConfig> { |
| 23 | + pre( |
| 24 | + "fileUpdate", |
| 25 | + mapOf( |
| 26 | + "file" to "src/main/resources/plugin.yml", |
| 27 | + "pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> "version: $v\\napi-version: \".+\"" }), |
| 28 | + "replacement" to KotlinClosure2<String, HookContext, String>({ v, _ -> "version: $v\napi-version: \"$mcApiVersion\"" }) |
| 29 | + ) |
| 30 | + ) |
| 31 | + // "normal" changelog update--changelog already contains a history |
| 32 | + pre( |
| 33 | + "fileUpdate", |
| 34 | + mapOf( |
| 35 | + "file" to "CHANGELOG.md", |
| 36 | + "pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> |
| 37 | + "\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/release-$v\\.\\.\\.HEAD\$([\\s\\S]*))?\\z" |
| 38 | + }), |
| 39 | + "replacement" to KotlinClosure2<String, HookContext, String>({ v, c -> |
| 40 | + """ |
| 41 | + \[Unreleased\] |
| 42 | + |
| 43 | + ## \[$v\] - ${currentDateString()}$1 |
| 44 | + \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD |
| 45 | + \[$v\]: https:\/\/github\.com\/$repoRef\/compare\/release-${c.previousVersion}...release-$v$2 |
| 46 | + """.trimIndent() |
| 47 | + }) |
| 48 | + ) |
| 49 | + ) |
| 50 | + // first-time changelog update--changelog has only unreleased info |
| 51 | + pre( |
| 52 | + "fileUpdate", |
| 53 | + mapOf( |
| 54 | + "file" to "CHANGELOG.md", |
| 55 | + "pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> |
| 56 | + "Unreleased([\\s\\S]+?\\nand this project adheres to \\[Semantic Versioning\\]\\(https:\\/\\/semver\\.org\\/spec\\/v2\\.0\\.0\\.html\\).)\\s\\z" |
| 57 | + }), |
| 58 | + "replacement" to KotlinClosure2<String, HookContext, String>({ v, c -> |
| 59 | + """ |
| 60 | + \[Unreleased\] |
| 61 | + |
| 62 | + ## \[$v\] - ${currentDateString()}$1 |
| 63 | + |
| 64 | + \[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD |
| 65 | + \[$v\]: https:\/\/github\.com\/$repoRef\/releases\/tag\/release-$v |
| 66 | + """.trimIndent() |
| 67 | + }) |
| 68 | + ) |
| 69 | + ) |
| 70 | + pre("commit") |
| 71 | + }) |
| 72 | +} |
| 73 | + |
| 74 | +fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE) |
| 75 | + |
| 76 | +java { |
| 77 | + sourceCompatibility = JavaVersion.VERSION_11 |
| 78 | + targetCompatibility = JavaVersion.VERSION_11 |
| 79 | +} |
| 80 | + |
| 81 | +repositories { |
| 82 | + jcenter() |
| 83 | + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") |
| 84 | + maven("https://oss.sonatype.org/content/repositories/snapshots") |
| 85 | +} |
| 86 | + |
| 87 | +dependencies { |
| 88 | + implementation(kotlin("stdlib-jdk8")) |
| 89 | + compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+") |
| 90 | +} |
| 91 | + |
| 92 | +ktlint { |
| 93 | + // FIXME - ktlint bug(?): https://github.com/pinterest/ktlint/issues/527 |
| 94 | + disabledRules.set(listOf("import-ordering")) |
| 95 | +} |
| 96 | + |
| 97 | +tasks { |
| 98 | + wrapper { |
| 99 | + gradleVersion = "6.1.1" |
| 100 | + distributionType = Wrapper.DistributionType.ALL |
| 101 | + } |
| 102 | + |
| 103 | + compileKotlin { |
| 104 | + kotlinOptions { |
| 105 | + jvmTarget = "1.8" |
| 106 | + } |
| 107 | + } |
| 108 | + |
| 109 | + // standard jar should be ready to go with all dependencies |
| 110 | + shadowJar { |
| 111 | + minimize() |
| 112 | + archiveClassifier.set("") |
| 113 | + } |
| 114 | + |
| 115 | + // nokt jar without the kotlin runtime |
| 116 | + register<ShadowJar>("nokt") { |
| 117 | + minimize() |
| 118 | + archiveClassifier.set("nokt") |
| 119 | + from(sourceSets.main.get().output) |
| 120 | + configurations = listOf(project.configurations.runtimeClasspath.get()) |
| 121 | + |
| 122 | + dependencies { |
| 123 | + exclude(dependency("org.jetbrains.*:")) |
| 124 | + } |
| 125 | + } |
| 126 | + |
| 127 | + build { |
| 128 | + dependsOn(":shadowJar", ":nokt") |
| 129 | + } |
| 130 | +} |
0 commit comments