From 7c9f537d79c1b14b450fceecfea0f5b135c5ae20 Mon Sep 17 00:00:00 2001 From: Oscar Westra van Holthe - Kind Date: Mon, 8 Apr 2024 18:30:24 +0200 Subject: [PATCH] Enhance publication build This makes two enhancements: 1. Publish builds require a non-snapshot version. 2. The published version is copied to the archive directory. --- build.gradle.kts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index d24389e..93f6e55 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import org.gradle.tooling.BuildException import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel import java.util.* @@ -354,7 +355,31 @@ tasks { // jq -r 'to_entries|map({key,"value":.value|map({majorVersion,version}|select(.majorVersion|test("202.\\..")))|unique|group_by(.majorVersion)|map(last(.[]))|map(.version)}|{key,"version":.value[]}|(.key+"-"+.version))|.[]' } + /** Fail the build if it has a SNAPSHOT version */ + register("requireNonSnapshotBuild") { + doFirst { + val version = project.version.toString() + if (version == "unspecified") { + throw GradleException("No version set") + } + if (version.endsWith("-SNAPSHOT")) { + throw GradleException("Cannot publish snapshot builds") + } + } + } + + /** Copies files from "build/distributions" to "demo" directory */ + register("archiveBuildArtifact") { + println("Archiving Build Artifacts") + from(layout.buildDirectory.dir("distributions")) + include("**/*.*") + into(layout.projectDirectory.dir("../archive-avro-schema-support")) + } + publishPlugin { + dependsOn("requireNonSnapshotBuild") + finalizedBy("archiveBuildArtifact") + // jetbrainsToken is set in ~/.gradle/gradle.properties, so the secret is not stored in git token.set(providers.gradleProperty("jetbrainsToken")) }