Alô! Exception in thread "main" java.util.Service...
# hoplite
l
Alô! Exception in thread "main" java.util.ServiceConfigurationError: com.sksamuel.hoplite.decoder.Decoder: Provider com.sksamuel.hoplite.decoder.LocaleDecoder not found I'm getting this exception when trying to package an UberJar using hoplite. It's a niche Jetpack Compose Desktop app. How to start understanding this error? I think it's because Hoplite depends on java meta but compose is not packing them
c
when creating an uber/shadow jar you need to merge service descriptors under META-INF; generally build tooling that creates these jars has an option to do so.
l
Unfortunately compose doesn't expose the shadow jar configuration, it uses it's own mechanism for an uber jar. Would you happen to know how to do this is compose desktop?
c
I have not used compose desktop; this article shows a potential solution (
mergeServiceFiles()
is what you want)
🫶 1
l
Unfortunately the error is still the same
Copy code
val shadowJar by tasks.named<ShadowJar>("shadowJar") {
    dependsOn(configurations)
    minimize {
        exclude(dependency(dependencies.compose.desktop.macos_x64))
        exclude(dependency(dependencies.compose.desktop.macos_arm64))
        exclude(dependency(dependencies.compose.desktop.linux_x64))
        exclude(dependency(dependencies.compose.desktop.linux_arm64))
        exclude(dependency(dependencies.compose.desktop.windows_x64))
    }
    // Some default shadow setup
    mergeServiceFiles()
    isReproducibleFileOrder = true
    archiveClassifier = null as String?
    archiveVersion = "$version-desktop"
    archiveBaseName = project.name
    // Relocate output jar into other folder
    layout.buildDirectory.dir("libs").get().asFile.also { destinationDirectory = it }
    // Don't forget to point into Main file which contains main() function
    manifest {
        attributes("Main-Class" to "br.com.colman.pikframe.MainKt")
    }
}
Is there a way to manually configure this instead of depending on service loaders? I'm ok with doing it once
c
you can call addDecoder() or somesuch on the builder to add decoders - that’s what is happening behind the scenes for the built-in ones.
l
There are way too many decoders to add to get Hoplite up
Reducing the shadowjar to this apparently made it work
Copy code
val shadowJar by tasks.named<ShadowJar>("shadowJar") {
    dependsOn(configurations)
    // Some default shadow setup
    mergeServiceFiles()
    isReproducibleFileOrder = true
    archiveClassifier = null as String?
    archiveVersion = "$version-desktop"
    archiveBaseName = project.name
    // Relocate output jar into other folder
    layout.buildDirectory.dir("libs").get().asFile.also { destinationDirectory = it }
    // Don't forget to point into Main file which contains main() function
    manifest {
        attributes("Main-Class" to "br.com.colman.pikframe.MainKt")
    }
}
It's no longe optimized, but that's a different issue
s
Maybe we should register all built in decoders without thr service files