Sayak Mukhopadhyay
06/14/2024, 2:09 PMgradlew bootJar is executed from the terminal. Is there a flag associated with the bootJar task that can allow me to change the filename? I know it can done by configuring the build.gradle file but that's not what I am looking for.Vampire
06/14/2024, 3:48 PM./gradlew help --task bootJar.
If not, you could have an init script that makes the necessary changes and include that using -I.Sayak Mukhopadhyay
06/14/2024, 3:52 PMversion in build.gradle.Vampire
06/14/2024, 3:53 PMversion on bootJar to null I guessSayak Mukhopadhyay
06/14/2024, 3:55 PMbuild.gradle file edit it with sed right before I build and restore the backup after build. Seems very hacky...Sayak Mukhopadhyay
06/14/2024, 4:26 PMChris Lee
06/14/2024, 4:33 PMSayak Mukhopadhyay
06/14/2024, 4:39 PMChris Lee
06/14/2024, 4:39 PMSayak Mukhopadhyay
06/14/2024, 4:44 PMChris Lee
06/14/2024, 4:45 PMmv build/libs/<name>-*.jar <dest>/<name>.jar or somesuch will do it (<name> is generally the known project name, the wildcard handles the version), if you’re not able to modify the build script accordingly.Sayak Mukhopadhyay
06/14/2024, 4:48 PMChris Lee
06/14/2024, 4:49 PM<name> is a well-known value, generally the project name. Is there some additional unstated requirement preventing using that well known name?Sayak Mukhopadhyay
06/14/2024, 4:50 PMChris Lee
06/14/2024, 4:51 PMmv build/libs/<name>-*.jar <dest>/<name>.jarSayak Mukhopadhyay
06/14/2024, 4:54 PMChris Lee
06/14/2024, 4:54 PMChris Lee
06/14/2024, 4:55 PMclean before building)Sayak Mukhopadhyay
06/14/2024, 4:57 PMVampire
06/14/2024, 5:55 PMversion property of the bootJar task to null and use it with -I parameter or by putting it to ~/.gradle/init.d/.Sayak Mukhopadhyay
06/15/2024, 7:17 AMbootJar {
version = null
}
Gives the error: Could not find method bootJar() for arguments [init_4dts4ab5klk4h2jow1p9qaoa7$_run_closure1@557b2fb0] on build of type org.gradle.invocation.DefaultGradle.
gradle.projectsEvaluated {
bootJar {
version = null
}
}
Same error as above
gradle.allprojects {
task bootJar {
version = null
}
}
Gives the error: Cannot add task 'bootJar' as a task with that name already exists. This one is due to build.gradle also creating that task, so I wrote the next one
gradle.projectsEvaluated {
tasks.whenTaskAdded { task ->
if (task.name == 'bootJar') {
project.version = null
}
}
}
Gives the error: Could not get unknown property 'tasks' for build. So next I tried using allprojects instead and that builds but doesn't change the jar name.
Sorry for the wall of text but I am at a loss here. I would love to use a gradle way of doing this still but I just cant seem to figure out the correct script.Vampire
06/15/2024, 8:19 AMBootJar is a subclass of Jar, so the property you want to set is archiveVersion. And don't use whenTaskAdded, that completely breaks task configuration avoidance. Use tasks.named { it == "bootJar" }.configureEach { ... }.Sayak Mukhopadhyay
06/15/2024, 10:50 AMgradle.projectsEvaluated {
tasks.named { it == "bootJar" }.configureEach {
archiveFileName.set("my.jar")
}
}
and
tasks.named { it == "bootJar" }.configureEach {
it.archiveFileName.set("my.jar")
}
They are all giving me the error Could not get unknown property 'tasks' for build of type org.gradle.invocation.DefaultGradle. Instead doing
gradle.allprojects {
tasks.named { it == "bootJar" }.configureEach {
archiveFileName.set("my.jar")
}
}
is giving the error No signature of method: org.gradle.api.internal.tasks.DefaultTaskContainer.named() is applicable for argument types. So, I tried doing
gradle.allprojects {
tasks.named ("bootJar").configureEach {
archiveFileName.set("my.jar")
}
}
which gives me Task with name 'bootJar' not found in root project. Honestly, I have no idea what I am doing wrong...Vampire
06/15/2024, 6:59 PMtasks.named { ... } works lazy, tasks.named(...) not.
But tasks.named { ... } is pretty young. If it complains that it does not exist, your Gradle version is too old. Either use a recent Gradle version, or alternatively use tasks.matching { it.name == "bootJar" }.configureEach { ... }Sayak Mukhopadhyay
06/15/2024, 7:10 PM