Actually, it is broken since log4j:log4j:1.2.15 and above.
The problem is that, due to error in the generated META-INF/MANIFEST.MF , it is not possible to determine the version of log4j / reload4j programatically.
This is due to an invalide Name:
entry in the manifest.
This is a problem because it is then difficult to log, or access the reload4j version from code (for example, to check if you let the CVEs behind..)
- version detection works with:
Name: org/apache/log4j/
- but is broken with the current:
Name: org.apache.log4j
I'm not sure if I can make a pull request on reload4j, put the following git diff fixes the problem for me:
diff --git a/pom.xml b/pom.xml
index 1f54ec10..579cedc5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -202,11 +202,19 @@
<version>${maven-jar-plugin.version}</version>
<configuration>
<archive>
+ <manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
</manifestEntries>
+ <manifestSections>
+ <manifestSection>
+ <name>org/apache/log4j/</name>
+ </manifestSection>
+ </manifestSections>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
Sample code for programatically acessing the version (as for other maven artifacts), but only works with a built jar:
@Test
public void testLog4jVersion() {
String implementationVersion = org.apache.log4j.PatternLayout.class.getPackage().getImplementationVersion();
LOGGER.warn("log4j.version="+implementationVersion);
assertNotNull(implementationVersion);
}