From 594d00bd93836f862961a05890ea3a205a20dde2 Mon Sep 17 00:00:00 2001 From: Bram Date: Mon, 8 Jul 2024 18:45:25 +0200 Subject: [PATCH] Improved: Default build task --- build.gradle.kts | 54 +++++++++++++++++-- .../entitylib.library-conventions.gradle.kts | 11 ++++ jitpack.yml | 5 +- 3 files changed, 61 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 177f4d3..40811c0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,9 +1,5 @@ import java.io.ByteArrayOutputStream -plugins { - entitylib.`library-conventions` -} - group = "me.tofaa.entitylib" description = rootProject.name val fullVersion = "2.4.1" @@ -24,4 +20,52 @@ fun getVersionMeta(): String { } return "$commitHash-SNAPSHOT" } -version = "$fullVersion${getVersionMeta()}" \ No newline at end of file +version = "$fullVersion${getVersionMeta()}" + +tasks { + wrapper { + gradleVersion = "8.8" + distributionType = Wrapper.DistributionType.ALL + } + + register("build") { + // Filter out the 'platforms' directory itself, but include its subprojects + val subModuleBuildTasks = subprojects + .filter { it.name != "platforms" } + .mapNotNull { it.tasks.findByName("build") } + + dependsOn(subModuleBuildTasks) + group = "build" + + doLast { + val buildOut = project.layout.buildDirectory.dir("libs").get().asFile.apply { + if (!exists()) mkdirs() + } + + subprojects.forEach { subproject -> + val subIn = subproject.layout.buildDirectory.dir("libs").get().asFile + if (subIn.exists()) { + copy { + from(subIn) { + include("EntityLib-*.jar") + exclude("*-javadoc.jar", "*-sources.jar") + } + into(buildOut) + } + } + } + } + } + + register("clean") { + val cleanTasks = subprojects + .filter { it.name != "platforms" } + .mapNotNull { it.tasks.findByName("clean") } + + dependsOn(cleanTasks) + group = "build" + delete(rootProject.layout.buildDirectory) + } + + defaultTasks("build") +} diff --git a/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts b/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts index e4718a2..a030ed9 100644 --- a/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/entitylib.library-conventions.gradle.kts @@ -47,4 +47,15 @@ tasks { } defaultTasks("build") +} + +// So that SNAPSHOT is always the latest SNAPSHOT +configurations.all { + resolutionStrategy.cacheDynamicVersionsFor(0, TimeUnit.SECONDS) +} + +val taskNames = gradle.startParameter.taskNames +if (taskNames.any { it.contains("build") } + && taskNames.any { it.contains("publish") }) { + throw IllegalStateException("Cannot build and publish at the same time.") } \ No newline at end of file diff --git a/jitpack.yml b/jitpack.yml index 2a3eb9d..eea24d2 100644 --- a/jitpack.yml +++ b/jitpack.yml @@ -1,5 +1,2 @@ jdk: - - temurin-21 - -install: - - ./gradlew clean build + - temurin-21 \ No newline at end of file