badass-jlink-plugin
badass-jlink-plugin copied to clipboard
jlink issues with Log4j 2.18.0 / 2.19.0 / 2.20.0 / 2.21.x
Opening a new issue because after the fix from this one https://github.com/beryx/badass-jlink-plugin/issues/14
It seems like the problem has returned for log4j 2.19.0
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
forceMerge('log4j-api' )
...
}
dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
}
When running the jlinked binary, you will get an error very similar to:
java.util.ServiceConfigurationError: org.apache.logging.log4j.spi.Provider: module com.codedead.merged.module does not declare `uses`
...
ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
ERROR StatusLogger Unable to load services for service interface org.apache.logging.log4j.core.util.ContextDataProvider
For anyone facing this issue, I've found a work-around by manually adding the following 'uses' statements to your mergedModule block:
jlink {
...
mergedModule {
additive = true
uses 'org.apache.logging.log4j.util.PropertySource';
uses 'org.apache.logging.log4j.core.util.ContextDataProvider';
uses 'org.apache.logging.log4j.core.util.WatchEventService';
uses 'org.apache.logging.log4j.spi.Provider';
uses 'org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory';
}
}
I filed same issue months ago here
https://github.com/beryx-gist/badass-jlink-example-log4j2-javafx/issues/5
I also manually added uses clauses but it is not working for all cases.
Hopefully it gets fixed soon.
I just ran into this same issue, thanks for logging it, and for posting a work-around, it saved me many hours of head-scratching!
According to the log4j 2.21.0 release notes they migrated from automatic modules to named modules. This might or might not solve this problem. Note that the module names for the bridge implementations changed.
According to the log4j 2.21.0 release notes they migrated from automatic modules to named modules. This might or might not solve this problem. Note that the module names for the bridge implementations changed.
No luck there unfortunately. There's a new error message in 2.21.0: Module org.apache.logging.log4j.core does not read a module that exports javax.annotation.processing
Going to look for a work-around.
As per https://github.com/apache/logging-log4j2/issues/1896 , the solution for log4j2 2.21.0 is to do something like this in your build.gradle file:
jlink {
forceMerge('log4j-api')
mergedModule {
additive = true
uses 'org.apache.logging.log4j.util.PropertySource'
uses 'org.apache.logging.log4j.spi.Provider'
uses 'org.apache.logging.log4j.message.ThreadDumpMessage.ThreadInfoFactory'
}
You will also need to add the following to your module-info:
requires java.compiler;
requires java.naming;
requires org.apache.logging.log4j;
requires org.apache.logging.log4j.core;