Files
distant-horizons-core-sharded/api/build.gradle
T
2026-04-18 12:07:24 -05:00

113 lines
3.6 KiB
Groovy

import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
id "java"
id "com.gradleup.shadow"
}
repositories {
mavenCentral()
}
tasks.withType(JavaCompile).configureEach {
options.release = 8
options.encoding = "UTF-8"
}
configurations {
testImplementation.extendsFrom compileOnly
}
dependencies {
compileOnly "org.apache.logging.log4j:log4j-api:${rootProject.log4j_version}"
testImplementation "junit:junit:4.13"
}
java {
withSourcesJar()
}
task addSourcesToCompiledJar(type: ShadowJar) {
mustRunAfter sourcesJar
// 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 class files from: \n" +
"[" + compiledJarPath + "] to source API jar: \n" +
"[" + shadowJar.archiveFile.get().asFile + "]")
// Validate the input JAR file
if (!compiledJarFile.exists()) {
throw new GradleException("Compiled JAR file not found: [${compiledJarFile}]")
}
}
// Set the name of the combined JAR file
archiveFileName.set("DistantHorizonsApi-${rootProject.api_version}.jar")
// Set the destination directory for the combined JAR file
destinationDirectory = file('build/libs/')
// Set the input JAR files to be combined
from sourceSets.main.allJava
from {
project.configurations.shadow.collect { it.isDirectory() ? it : zipTree(it) }
}
// 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
eachFile { file ->
// can be set to true for debugging
def useAlternateEmbedMethod = false
def showFileEmbedding = false
if (showFileEmbedding || useAlternateEmbedMethod) {
System.out.println("attempting to add file: " + file)
def relativePath = file.relativePath.pathString
if (relativePath.endsWith('.class')) {
System.out.println("class file: " + relativePath)
def sourceFile = file.file.parentFile.resolveSibling('src/main/java/' + relativePath.replace('.class', '.java'))
if (sourceFile.exists()) {
System.out.println("adding source file: " + sourceFile)
if (useAlternateEmbedMethod) {
file.withInputStream { inputStream ->
copy {
from(inputStream)
into(relativePath.replace('.class', '.java'))
}
}
}
} else {
System.out.println('missing source file: ' + sourceFile)
}
}
}
}
}
shadowJar {
// required for basic shadowJar setup
configurations = [project.configurations.shadow]
finalizedBy(addSourcesToCompiledJar)
}
javadoc {
options {
// Don't log warnings.
// There are a lot of warnings related to missing @param and @return javadocs
// that aren't necessary and would clutter up said javadocs.
// For more info see: https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javadoc.html
addStringOption('Xdoclint:all,-missing', '-quiet')
}
}