I’m trying to include some resources download from a zip file in a jar, but it seems that on the first build of the application, they are not included in the jar.
Here is a minimal build.gradle.kts (full one can be found here): (I’ve included anything that remotely has anything to do with build, just in case)
plugins {
java
id("com.github.johnrengelman.shadow").version("6.1.0")
}
repositories {
//repos
}
dependencies {
//deps
}
val compileJava: JavaCompile by tasks
val mainSourceSet: SourceSet = sourceSets["main"]
val tokenizeJavaSources = task<Copy>(name = "tokenizeJavaSources") {
from(mainSourceSet.allSource) {
include("**/plugin.yml")
println("version: $versionObj")
val tokens = mapOf("VERSION" to versionObj.toString())
filter(org.apache.tools.ant.filters.ReplaceTokens::class, "tokens" to tokens)
}
into("build/tokenizedSources")
includeEmptyDirs = false
}
compileJava.apply {
dependsOn(tokenizeJavaSources)
options.encoding = "UTF-8"
doFirst {
options.compilerArgs = mutableListOf("-Xlint:all")
}
}
val downloadDefaultPacks = tasks.create("downloadDefaultPacks") {
doFirst {
file("${buildDir}/resources/main/packs/").deleteRecursively()
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
downloadAndUnzipPack(defaultPackUrl)
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
downloadAndUnzipPack(netherPackUrl)
} //I've duplicated this code twice, so that it runs both before the actual running of tasks, and during the running of tasks.
file("${buildDir}/resources/main/packs/").deleteRecursively()
val defaultPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/default.zip")
downloadAndUnzipPack(defaultPackUrl)
val netherPackUrl = URL("https://github.com/PolyhedralDev/TerraDefaultConfig/releases/download/latest/nether.zip")
downloadAndUnzipPack(netherPackUrl)
}
tasks.compileJava {
dependsOn(downloadDefaultPacks)
}
tasks.named<ShadowJar>("shadowJar") {
from(tokenizeJavaSources.destinationDir)
dependsOn(downloadDefaultPacks)
archiveClassifier.set("shaded")
archiveBaseName.set("Terra")
setVersion(project.version)
//relocations
minimize {
exclude(project(":")) //root project
}
}
tasks.build {
dependsOn(tasks.shadowJar)
dependsOn(downloadDefaultPacks)
tasks.shadowJar.get().mustRunAfter(downloadDefaultPacks)
}
I think the issue has something to do with the fact that those files do not exist at the start of the execution, so perhaps Gradle is indexing them or something and then later doesn’t include them?
To run this, I’m running ./gradlew build -x test
. (Skipping tests because they’re broken + they take a long time.)
I’ve also tried just running ./gradlew shadowJar
. Nothing works.
You can test this by cloning the repo this is in with git clone -b gh-builds git@github.com:solonovamax/Terra.git
, then running ./gradlew build -x test
. The produced jar should be about 496kb. Running it again will produce a jar that is ~1.8mb.