Building Log4j Core
Log4j 2 supports the Java Platform Module System. JPMS has requirements that conflict with several things Log4j also tries to support:
- OSGi - OSGi frameworks are not packaged as OSGi modules. Including an OSGi implementation will cause compiler errors while resolving the JPMS module inforation.
- Garbage Free - The Google tool Log4j uses to verify that Log4j core is garbage free violates JPMS rules. The test compilations fail when it is included as a dependency.
- Compiler bugs - When compiling with module-info.java included the classes in the appender, layout, and filter directories get “duplicate class” errors. For some reason these directory names are being interpreted as starting with upper case letters even though they are not. For some reason the compiler is showing an error that the class cannot be found even though it is being generated. See JDK-8265826.
- Test classes that are used by other modules - Several test classes are used by other log4j modules and need to be passed to them. This requires these classes exist in a package that is not used in log4j-core.
- Test classes used by log4j-core must use the same package space to be able to access some methods in the classes being tested.
- Once Java has compiled the main module with a module-info.java all test compiles also require one. Likewise, a test compile with a module-info.java is not allowed if the main compile doesn't have one.
For these reasons the build will need to be processed as follows:
- Move the Garbage Free tests to their own module. This will require copying all the test resources.
- Compile all the main classes except module-info.java with the Plugin preprocessor.
- Compile the main module-info.java.
- Compile the test classes used by other modules with module-info.java and with the plugin preprocessor.
- Package these test classes in a test jar.
- Delete the module-info and generated source for the test classes.
- Move the main module-info to a temp location.
- Compile the unit test classes without module-info.java.
- Move the main module-info back to the classes directory.
- Compile module-info.java for unit tests.
- Run the unit tests.
- Create the main jar if the unit tests pass.
Once the JDK bug is fixed this process can be simplified quite a bit since the components will all be able to be compiled once with the module-info.java file.