上下文
我在一个依赖于库的存储库中将Java版本从8升级到17。我想用Java 17构建存储库,但用Java 8构建库,因为它不能用Java 8构建。
环境
Docker容器与Java 17,但也与Java 8。
问题
存储库通过在库中运行ant任务来构建库
<ant dir="${lib-build-top}" target="all"/>
<ant dir="${lib-build-top}" target="buildjars"/>在终端中,可以用来构建图书馆
JAVA_HOME=path/to/jdk8 ant所以我想做一些像这样的事情
set JAVA_HOME and java.home from jdk17 to jdk8
<ant dir="${lib-build-top}" target="all"/>
<ant dir="${lib-build-top}" target="buildjars"/>
change JAVA_HOME and java.home back to jdk17我该怎么做呢?
发布于 2021-09-09 13:32:48
我认为唯一的方法是使用不同的JAVA_HOME环境变量派生一个新的Ant流程。在the documentation of 中甚至有这样一个运行Ant的例子
<condition property="jdk8-home"
value="C:\Program Files\Java\jdk1.8.0_301">
<os family="windows"/>
</condition>
<property name="jdk8-home" location="/usr/lib/jvm/java-8-openjdk-amd64"/>
<property name="ant-executable" location="${ant.home}/bin/ant"/>
<exec osfamily="unix" executable="${ant-executable}">
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="all"/>
<env key="JAVA_HOME" file="${jdk8-home}"/>
</exec>
<exec osfamily="windows" executable="cmd">
<arg value="/c"/>
<arg file="${ant-executable}.bat"/>
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="all"/>
<env key="JAVA_HOME" file="${jdk8-home}"/>
</exec>
<exec osfamily="unix" executable="${ant-executable}">
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="buildjars"/>
<env key="JAVA_HOME" file="${jdk8-home}"/>
</exec>
<exec osfamily="windows" executable="cmd">
<arg value="/c"/>
<arg file="${ant-executable}.bat"/>
<arg value="-buildfile"/>
<arg file="${ant.file}"/>
<arg value="buildjars"/>
<env key="JAVA_HOME" file="${jdk8-home}"/>
</exec>https://stackoverflow.com/questions/69117486
复制相似问题