Remove dependency on missing UnixSystem class
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/security/auth/module/UnixSystem
at org.freedesktop.dbus.connections.SASL.getUserId(SASL.java:757)
at org.freedesktop.dbus.connections.SASL.auth(SASL.java:459)
at org.freedesktop.dbus.connections.transports.AbstractTransport.authenticate(AbstractTransport.java:254)
at org.freedesktop.dbus.connections.transports.AbstractTransport.internalConnect(AbstractTransport.java:230)
at org.freedesktop.dbus.connections.transports.AbstractTransport.connect(AbstractTransport.java:177)
at org.freedesktop.dbus.connections.transports.TransportBuilder.build(TransportBuilder.java:213)
at org.freedesktop.dbus.connections.base.AbstractConnectionBase.<init>(AbstractConnectionBase.java:114)
at org.freedesktop.dbus.connections.base.ConnectionMethodInvocation.<init>(ConnectionMethodInvocation.java:33)
at org.freedesktop.dbus.connections.base.ConnectionMessageHandler.<init>(ConnectionMessageHandler.java:42)
at org.freedesktop.dbus.connections.AbstractConnection.<init>(AbstractConnection.java:41)
at org.freedesktop.dbus.connections.impl.DBusConnection.<init>(DBusConnection.java:72)
at org.freedesktop.dbus.connections.impl.DBusConnectionBuilder.build(DBusConnectionBuilder.java:176)
Some more context would be helpful.
The call to UnixSystem is completely valid on any *nix OS.
Do you use a custom tailored JRE and forgot to include the jdk.security.auth module?
I'm encountering the same error when running in distribution mode, using OpenJDK or JetBrains Runtime. How can I resolve this?
As said before, I need more details to understand what the issue is. I don't speak Portuguese and the few information I can see using google translate does not help in any way.
I use the Eclipse (Temurin) JDK on Linux and this is working fine. The required module is declared in modules-info file so no JPMS issue as far as I can see.
I don't know JetBrains Runtime, but as far as I can see the requested class is also present in this environment.
I apologize. I document my issues in Portuguese because it’s easier for me, but I realize this creates a barrier. I'll work on improving my English and start documenting everything in English.
Thank you for your willingness to help; your comments have already given me some direction. Now, I just need to figure out how to resolve this issue in my specific setup, which involves a Compose for Desktop application.
From what I've investigated so far, the UnixSystem class is missing only in distribution mode, regardless of whether it’s executed from the IDE or from the system, whereas it works fine in debug mode, which is why I didn’t notice this issue during development.
As you pointed out, UnixSystem is part of the JetBrains Runtime, so it doesn’t appear to be related to this specific JDK. I can use UnixSystem directly, and the error only arises when I compile in distribution mode (ProGuard is disabled).
To be sure, I tested with other JDKs (Azul, Corretto, and OpenJDK) with the same result. I also confirmed that the jdk.security.auth module is present in both the JDK I use for development (JetBrains Runtime) and the JRE installed on my PC.
I'll continue investigating and will document the solution here for future reference.
I managed to solve the issue! I needed to include the module directly, just as you suggested.
compose.desktop {
application {
...
nativeDistributions {
modules("jdk.security.auth")
...
}
}
}
It took me a while because, at first, I tried using jvmArgs, but that wasn’t working.
compose.desktop {
application {
...
nativeDistributions {
// does not work
jvmArgs += listOf("-add-modules", "jdk.security.auth")
...
}
}
}
I also tried using the JavaExec or CompileJava tasks.
tasks.withType<JavaExec> {
// does not work
jvmArgs = listOf("--add-modules", "jdk.security.auth")
}
Something I hadn’t noticed before was a Gradle task called ./gradlew suggestRuntimeModules, which, when run, suggests the missing modules to include and even explains how to add them. It was a simple case of my lack of experience.
After studying a bit more, I understood why this issue occurs, and only in the distribution build. When you generate a distribution with Compose for Desktop, it includes an embedded Java runtime with the minimum necessary to run the application, thus eliminating the need for a Java installation on the user's system. The embedded JRE was the one that didn’t contain the required module.