Skip to content

Commit

Permalink
Fixed build issue with thg FatJar.kt to allow the gui-app to be built…
Browse files Browse the repository at this point in the history
… using the new Gradle 8.12
  • Loading branch information
flemming-n-larsen committed Jan 1, 2025
1 parent 70e33ea commit 4a0af05
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions buildSrc/src/main/kotlin/build/tasks/FatJar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package build.tasks
import org.gradle.api.file.DuplicatesStrategy
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.bundling.Jar
import java.io.File

abstract class FatJar : Jar() {
private val jarManifestVendor = "robocode.dev"
Expand All @@ -22,31 +22,42 @@ abstract class FatJar : Jar() {
@get:Optional
abstract val outputFilename: Property<String?>

private val compileClasspath = project.configurations.getByName("compileClasspath").resolve()
private val runtimeClasspath = project.configurations.getByName("runtimeClasspath").resolve()
// Declare configurations as inputs
@get:InputFiles
protected val compileClasspath = project.configurations.getByName("compileClasspath")

@TaskAction
fun taskAction() {
@get:InputFiles
protected val runtimeClasspath = project.configurations.getByName("runtimeClasspath")

init {
// Move configuration to init block
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}

@TaskAction
override fun copy() { // Change to override copy() instead of custom taskAction
if (outputFilename.isPresent) {
archiveFileName.set(outputFilename)
}

manifest {
it.attributes["Implementation-Title"] = title.get()
it.attributes["Implementation-Version"] = archiveVersion
it.attributes["Implementation-Vendor"] = jarManifestVendor
it.attributes(mapOf(
"Implementation-Title" to title.get(),
"Implementation-Version" to archiveVersion,
"Implementation-Vendor" to jarManifestVendor
))
if (mainClass.isPresent) {
it.attributes["Main-Class"] = mainClass.get()
}
}

from(
File("build/classes/kotlin/main"),
File("build/classes/java/main"), // Bot API is written in Java
File("build/resources/main"),
project.files("build/classes/kotlin/main"),
project.files("build/classes/java/main"), // Bot API is written in Java
project.files("build/resources/main"),

compileClasspath.filter { it.name.endsWith(".jar") }.map { project.zipTree(it) },
runtimeClasspath.filter { it.name.endsWith(".jar") }.map { project.zipTree(it) }
runtimeClasspath.filter { it.name.endsWith(".jar") }.map { project.zipTree(it) },
)
exclude("*.kotlin_metadata")

Expand Down

0 comments on commit 4a0af05

Please sign in to comment.