Thank you, that was very helpful.
For completeness, here is the script that seems to work for me; at
least, maven runs to completion.
(Might want to remove the jdk 7 section from toolchains-sample-mac.xml
in git...?)
http://kegel.com/install-log4j2-mac.sh.txt
- Dan
On Sun, Dec 19, 2021 at 10:19 PM Ralph Goers <[email protected]> wrote:
>
> Also, make sure you are building the release-2.x branch. The master branch
> will build with Maven and targets Java 11 but it u
> ses some strange mechanics to get around the quirks of JPMS and this will
> make it a mess in your IDE. Once things get back
> to normal I plan to fix up the master branch using suggestions we got from
> the Maven team.
>
> Ralph
>
> > On Dec 19, 2021, at 11:15 PM, Ralph Goers <[email protected]>
> > wrote:
> >
> > You must run the build with Java 8 as the default JDK. You need a toolchain
> > for Java 9 or greater. I’d recommend Java 11.
> >
> > Ralph
> >
> >> On Dec 19, 2021, at 10:53 PM, Dan Kegel <[email protected]> wrote:
> >>
> >> Hi all!
> >>
> >> I'm trying to write an ide-free shell script to reproducibly build log4j
> >> from
> >> git on a fresh mac, following
> >> https://logging.apache.org/log4j/2.x/build.html and filling in the
> >> blanks. My current draft,
> >> http://kegel.com/install-log4j2-mac.sh.txt
> >> installs
> >> https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.dmg
> >> and creates a toolchains.xml file:
> >> sed 's/java[789]/jdk-17.0.1.jdk/' < toolchains-sample-mac.xml >
> >> ~/.m2/toolchains.xml
> >>
> >> Not too surprisingly, that fails with
> >>
> >> [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]
> >> /Users/dank/logdemo/logging-log4j2/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
> >>
> >> I dimly recall sun.reflect going away (
> >> https://stackoverflow.com/questions/23808803/sun-reflect-reflection-getcallerclass-alternative
> >> says it was removed from jdk8), so perhaps the way my script sets up
> >> ~/.m2/toolchain.xml isn't sufficient. Is one supposed to add
> >> something to toolchain.xml to tell javac to target a different version
> >> of the jdk in each of the jdk7/8/9 sections? Or do I actually have to
> >> go dig up an ancient JDK 1.7 to make maven and log4j happy?
> >>
> >> https://blog.hcf.dev/article/2019-09-15-maven-toolchains-xml-script
> >> suggests the latter, ugh...
> >>
> >> Thanks,
> >> Dan Kegel
> >>
> >
> >
>
#!/bin/sh
# Building log4j2 2.x from scratch on Mac
set -ex
# Running "javac --version" points you to this download page if no javac is
installed
if ! test -d /Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk
then
if ! test -f jdk-17_macos-x64_bin.dmg
then
wget
https://download.oracle.com/java/17/latest/jdk-17_macos-x64_bin.dmg
fi
open jdk-17_macos-x64_bin.dmg
sudo installer -pkg /Volumes/JDK\ 17.0.1/JDK\ 17.0.1.pkg -target /
fi
javac --version
if ! test -d /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk
then
if ! test -f $HOME/Downloads/jdk-17_macos-x64_bin.dmg
then
open
https://www.oracle.com/java/technologies/javase/javase8-archive-downloads.html#license-lightbox
while ! test -f $HOME/Downloads/jdk-8u202-macosx-x64.dmg
do
sleep 1
done
fi
open $HOME/Downloads/jdk-8u202-macosx-x64.dmg
sudo installer -pkg "/Volumes/JDK 8 Update 202/JDK 8 Update 202.pkg"
-target /
fi
javac --version
if ! test -d apache-maven-2.8.4
then
# See https://maven.apache.org/install.html
if ! test -f apache-maven-3.8.4-bin.tar.gz
then
wget
https://dlcdn.apache.org/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz
fi
tar -xf apache-maven-3.8.4-bin.tar.gz
fi
PATH=$PWD/apache-maven-3.8.4/bin:$PATH
mvn --version
if ! test -f ~/.m2/toolchains.xml
then
mkdir -p ~/.m2
cat > ~/.m2/toolchains.xml << "_EOF_"
<?xml version="1.0" encoding="UTF8"?>
<toolchains>
<toolchain>
<type>jdk</type>
<provides>
<version>1.8</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
<toolchain>
<type>jdk</type>
<provides>
<version>17</version>
<vendor>sun</vendor>
</provides>
<configuration>
<jdkHome>/Library/Java/JavaVirtualMachines/jdk-17.0.1.jdk/Contents/Home</jdkHome>
</configuration>
</toolchain>
</toolchains>
_EOF_
fi
if ! test -d logging-log4j2
then
# See https://logging.apache.org/log4j/2.x/build.html
git clone --branch release-2.x https://github.com/apache/logging-log4j2
fi
# Make 1.8 the default java for this build
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8.0_202)
cd logging-log4j2
mvn install