习惯先用jdk1.8打包编译,由于源码里有java9相关的模块,jdk8出错
log4j-core-java9
log4j-api-java9
报错
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-toolchains-plugin:1.1:toolchain (default) on project log4j-api-java9: Cannot find matching toolchain definitions for the following toolchain types:
[ERROR] jdk [ version='[9, )' ]
[ERROR] Please make sure you define the required toolchains in your ~/.m2/toolchains.xml file.
单docker镜像里只有一个版本的jdk,准备环境要花点工夫,先试用用jdk11 打包
下载源码
Release log4j-2.15.0-rc2 · apache/logging-log4j2 (github.com)
apache/logging-log4j2 at log4j-2.15.0-rc2 (github.com)
编辑 logging-log4j2/toolchains-sample-linux.xml at log4j-2.15.0-rc2 · apache/logging-log4j2 (github.com)
**加速包下载...
mvn package -DskipTests=true
期间有出错
[INFO] Apache Log4j Spring Cloud Config Support ........... SKIPPED
[INFO] Apache Log4j Spring Cloud Config Client Support .... SKIPPED
[INFO] Apache Log4j Sample Configuration Service .......... SKIPPED
[INFO] Apache Log4j Spring Cloud Config Samples ........... SKIPPED
[INFO] Apache Log4j Spring Cloud Config Sample Application SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.294 s
[INFO] Finished at: 2021-12-10T12:17:13Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project log4j-api: Compilation failure
[ERROR] /tmp/logging-log4j2-log4j-2.15.0-rc2/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java:[25,18] error: cannot find symbol
[ERROR] symbol: class Reflection
[ERROR] location: package sun.reflect
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <args> -rf :log4j-api
由于是在docker里用openjdk编译,jdk环境可能不完整,这是测试代码,不影响功能为快速编译,直接删除后继续
rm /tmp/logging-log4j2-log4j-2.15.0-rc2/log4j-api/src/test/java/org/apache/logging/log4j/util/StackLocatorUtilTest.java
mvn package -DskipTests=true
编译还是很耗时,不必要的模块较多,注释跳过即可
原始所有模块
<modules>
<module>log4j-api-java9</module>
<module>log4j-api</module>
<module>log4j-core-java9</module>
<module>log4j-core</module>
<module>log4j-layout-template-json</module>
<module>log4j-core-its</module>
<module>log4j-1.2-api</module>
<module>log4j-slf4j-impl</module>
<module>log4j-slf4j18-impl</module>
<module>log4j-to-slf4j</module>
<module>log4j-jcl</module>
<module>log4j-flume-ng</module>
<module>log4j-taglib</module>
<module>log4j-jmx-gui</module>
<module>log4j-samples</module>
<module>log4j-bom</module>
<module>log4j-jdbc-dbcp2</module>
<module>log4j-jpa</module>
<module>log4j-couchdb</module>
<module>log4j-mongodb3</module>
<module>log4j-mongodb4</module>
<module>log4j-cassandra</module>
<module>log4j-web</module>
<module>log4j-jakarta-web</module>
<module>log4j-perf</module>
<module>log4j-iostreams</module>
<module>log4j-jul</module>
<module>log4j-jpl</module>
<module>log4j-liquibase</module>
<module>log4j-appserver</module>
<module>log4j-osgi</module>
<module>log4j-docker</module>
<module>log4j-kubernetes</module>
<module>log4j-spring-boot</module>
<module>log4j-spring-cloud-config</module>
</modules>
精简为
<modules>
<module>log4j-api-java9</module>
<module>log4j-api</module>
<module>log4j-core-java9</module>
<module>log4j-core</module>
<module>log4j-core-its</module>
<module>log4j-1.2-api</module>
<module>log4j-slf4j-impl</module>
<module>log4j-slf4j18-impl</module>
<module>log4j-to-slf4j</module>
</modules>
应该还能再精简
最后只需要两个包
root@6f0c9dbb976b:/tmp/logging-log4j2-log4j-2.15.0-rc2# md5sum log4j-api/target/log4j-api-2.15.0.jar
62a0c20d6345a721f17611f88d5714c9 log4j-api/target/log4j-api-2.15.0.jar
root@6f0c9dbb976b:/tmp/logging-log4j2-log4j-2.15.0-rc2# md5sum log4j-core/target/log4j-core-2.15.0.jar
d6ebc62e68365231ec12e0a28f2b742c log4j-core/target/log4j-core-2.15.0.jar
完成,准备用jdk9再试下