expert
10/18/2024, 4:09 PMopen class FatJarTask: Jar() {
init {
val configuration = project.configurations.getByName("runtimeClasspath")
manifest.apply {
attributes["Timestamp"] = System.currentTimeMillis()
}
project.plugins.withType(JavaPlugin::class.java) {
val sourceSets = project.extensions.getByType(SourceSetContainer::class.java)
from(sourceSets.getByName("main").output)
}
from(configuration.map { if (it.isDirectory) it else project.zipTree(it) }, {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
})
isZip64 = true
}
}
implemented in my custom gradle plugin (which is published to maven repo). When it's being used like this
tasks {
register<FatJarTask>("fatJar")
}
I get error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':project:fatJar'.
> Entry META-INF/LICENSE is a duplicate but no duplicate handling strategy has been set. Please refer to <https://docs.gradle.org/8.10.1/dsl/org.gradle.api.tasks.Copy.html#org.gradle.api.tasks.Copy:duplicatesStrategy> for details.
If I move implementation of this task as is to build.gradle.kts of the project that uses it there will be no error.
So, for some reason duplicatesStrategy is not set when task implementation is coming from external gradle plugin. What am I missing ?Martin
10/18/2024, 4:34 PMfrom(configuration.map { if (it.isDirectory) it else project.zipTree(it) }, {
it.duplicatesStrategy = DuplicatesStrategy.EXCLUDE
})Martin
10/18/2024, 4:35 PMit. )Martin
10/18/2024, 4:39 PMexpert
10/18/2024, 4:43 PMMartin
10/18/2024, 4:57 PMtasks.register("fatJar") {
// configure here
}Vampire
10/18/2024, 5:35 PMshadow plugin which at least sails around some of the cliffs you will hit sooner or later.
And you shouldn't use project.plugins (see its JavaDoc)expert
10/18/2024, 7:34 PMAnd you shouldn't useCould you please elaborate what you mean by this and perhaps demonstrate it with snippet of code?(see its JavaDoc)project.plugins
Vampire
10/18/2024, 7:39 PMbut I couldn't configure it to skip compileOnly dependenciesThat's probably because you configured it to include them somewhere. 😄 By default they are not included as that makes not sense. By default it uses
runtimeClasspath which usually exactly is what you need.
So after long fight with it I gave up and switched to vanilla Jar task.Do whatever works for you. Just saying that with that you have more quirks than you have anyway by using such bad-practice fat jars.
Could you please elaborate what you mean by this and perhaps demonstrate it with snippet of code?I'm not sure what you are asking for. You showed that you use
project.plugins.
And if you look at its JavaDoc it tells you you shouldn't use it and what to use instead.
So did you read its JavaDoc as I suggested?
If so, then I really don't understand the question, can you maybe reformulate it?