Hello, I have the following task to build a fatJar...
# community-support
r
Hello, I have the following task to build a fatJar:
Copy code
tasks.register<Jar>("buildFatJar") {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    isZip64 = true
    from(fatJar.map(::zipTree))
    with(tasks["jar"] as CopySpec)
}
This seems to be producing a bunch of deprecation errors in Gradle 7.6.2:
Copy code
Reason: Task ':project:buildFatJar' uses this output of task ':other-project:jar' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. This behaviour has been deprecated and is scheduled to be removed in Gradle 8.0.
I assume that this is due to the
from
clause in the task which explodes all the dependencies of the
fatJar
configuration into the fatJar. How can I make this task compatible with Gradle 8? Thanks!
v
The
.map
you use is not the one from
Provider
that preserves task dependencies, but the one from
Iterable<File>
. It not only looses the task dependency but is also evaluated eagerly. If you use
fatJar.elements
and work on that, for example call
.map
on it, it should work better I think.
r
Thanks @Vampire! Giving it a shot
πŸ‘Œ 1
v
Actually, if you really need to build such a bad practice fat jar, I'd at least use the shadow plugin of John Engelman which at least sails around some of the cliffs with them.
r
Thanks for the recommendation, I'll look into it. What would be a better-practice fat jar?
v
Imho the best practice is the not-fat jar, but building proper distributions. :-D The second-best option is doing it like Spring Boot does it.
r
By distributions, do you mean the distributions built by Gradle's application plugin?
Copy code
from(fatJar.elements.map(::zipTree))
Can't seem to pass elements.map into the from due to:
Copy code
Cannot fingerprint input file property 'rootSpec$1': Cannot convert the provided notation to a File or URI: [/path/some-jar.jar, ....].
The following types/formats are supported:
    - A String or CharSequence path, for example 'src/main/java' or '/usr/include'.
    - A String or CharSequence URI, for example 'file:/usr/include'.
    - A File instance.
    - A Path instance.
    - A Directory instance.
    - A RegularFile instance.
    - A URI or URL instance.
    - A TextResource instance.
I was hoping to be able to bend this into being compatible with Gradle 8. But if it's so against the grain, then I'll just try using the shadow plugin. Thanks for the advice.
v
By distributions, do you mean the distributions built by Gradle's application plugin?
For example, yes.
Can't seem to pass elements.map into the from due to:
You can, if you do it right. πŸ˜„
from(fatJar.elements.map(::zipTree))
compiles as
zipTree
accepts
Any
, but then fails as you give it a
Set<FileSystemLocation>
and that is what complains, not the
from
.
πŸ˜… 1
from(fatJar.elements.map { it.map(::zipTree) })
is what you intended
r
Awesome! Thanks a lot BjΓΆrn!
(Gradle syntax and semantics is hard sometimes)
v
Yes, sometimes. Kotlin DSL was a great improvement there for IDE support. But methods historically accepting any object and then checking the type are of course not too helpful, but cannot easily replaced due to backwards compatibility.
r
Oh absolutely. Kotlin in Gradle scripts was a godsend. Yes, understood. I would like to see Gradle deprecating Groovy for build scripts at some point though. That would be another boon for productivity
v
πŸ€·β€β™‚οΈ
r
Thanks again @Vampire
πŸ‘Œ 1
πŸŽ‰
πŸ‘Œ 1