From 0ef11caaf293c1f220ced47f69bf87d9d091797e Mon Sep 17 00:00:00 2001 From: James Seibel Date: Sat, 18 Apr 2026 12:07:24 -0500 Subject: [PATCH] API jar auto include sources --- api/build.gradle | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/api/build.gradle b/api/build.gradle index ec16716ea..091d6e625 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -23,25 +23,27 @@ dependencies { testImplementation "junit:junit:4.13" } -shadowJar { - // required for basic shadowJar setup - configurations = [project.configurations.shadow] +java { + withSourcesJar() } task addSourcesToCompiledJar(type: ShadowJar) { + + mustRunAfter sourcesJar - def sourceJarPath = "build/libs/DistantHorizons-api-${rootProject.versionStr}-sources.jar" - def secondJarFile = file(sourceJarPath) + // the compiled "-all" jar is used since it's available at the time this task is run + def compiledJarPath = "build/libs/api-api-${rootProject.versionStr}-all.jar" + def compiledJarFile = file(compiledJarPath) // doFirst is so these only run when the task is actually executed doFirst { - System.out.println("Adding source files from: \n" + - "[" + sourceJarPath + "] to compiled API jar: \n" + + System.out.println("Adding class files from: \n" + + "[" + compiledJarPath + "] to source API jar: \n" + "[" + shadowJar.archiveFile.get().asFile + "]") // Validate the input JAR file - if (!secondJarFile.exists()) { - throw new GradleException("Second JAR file not found: [${secondJarFile}]") + if (!compiledJarFile.exists()) { + throw new GradleException("Compiled JAR file not found: [${compiledJarFile}]") } } @@ -49,17 +51,16 @@ task addSourcesToCompiledJar(type: ShadowJar) { archiveFileName.set("DistantHorizonsApi-${rootProject.api_version}.jar") // Set the destination directory for the combined JAR file - destinationDirectory = file('build/libs/merged/') + destinationDirectory = file('build/libs/') // Set the input JAR files to be combined from sourceSets.main.allJava from { - configurations.shadow.collect { it.isDirectory() ? it : zipTree(it) } + project.configurations.shadow.collect { it.isDirectory() ? it : zipTree(it) } } - // set the jars to merge - from shadowJar.archiveFile.get().asFile - from secondJarFile + // add the class files + from zipTree(compiledJarFile) // alternative method to Include the source files in the combined JAR // and/or see which files are being included @@ -94,6 +95,12 @@ task addSourcesToCompiledJar(type: ShadowJar) { } +shadowJar { + // required for basic shadowJar setup + configurations = [project.configurations.shadow] + finalizedBy(addSourcesToCompiledJar) +} + javadoc { options { // Don't log warnings.