Gitlab ant.java.version is 11 but I want to build the project using another version

So I’m using gitlab and I have a java project that’s built on gitlab VM using a .gitlab-ci-yml file.

I have this problem where we have to change the java version the project is build with (current java 11).

So adding in build.xml this: <echo message="ant.java.version = ${ant.java.version}" /> will print 11.

I’ve tried to change it specifying in javac the source and target but if the target is not specified, it will not build it using another java version, and if it is specified, it will return an error:
enter image description here
Also using <property name="ant.build.javac.target" value="17" /> will return the same error.
So I’m not sure if basically adding my own ant tool and java version into the package and force it to use that one will work, I don’t know how to do this.

Here is the build.xml file and also the .gitlab-ci.yml

UPDATE: .gitlab-ci.yml was updated. Now the error seems to be the following, having the below .gilab-ci.yml file: Unable to locate package adoptopenjdk-17-hotspot
build.xml

<project name="ClinicalTrialProcessor" default="all" basedir=".">
<property name="build" value="${basedir}/build"/>
<property name="source" value="${basedir}/source"/>
<property name="java" value="${source}/java"/>
<property name="files" value="${source}/files"/>
<property name="resources" value="${source}/resources"/>
<property name="config" value="${source}/config"/>
<property name="installer" value="org/rsna/installer"/>
<property name="launcher" value="org/rsna/launcher"/>
<property name="runner" value="org/rsna/runner"/>
<property name="libraries" value="${basedir}/libraries"/>
<property name="products" value="${basedir}/products"/>
<property name="documentation" value="${basedir}/documentation"/>
<property name="title" value="CTP"/>
<property name="copyright" value="Copyright 2013 Radiological Society of North America"/>
<property name="ant.build.javac.target" value="17" />
<path id="classpath">
<pathelement location="${libraries}/util.jar"/>
<pathelement location="${libraries}/dcm4che.jar"/>
<pathelement location="${libraries}/getopt.jar"/>
<pathelement location="${libraries}/log4j.jar"/>
<pathelement location="${libraries}/edtftpj.jar"/>
<pathelement location="${libraries}/jdbm.jar"/>
<pathelement location="${libraries}/commons-compress-1.0.jar"/>
<pathelement location="${libraries}/jai_imageio.jar"/>
<pathelement location="${libraries}/pixelmed_codec.jar"/>
<pathelement location="${libraries}/email/activation.jar"/>
<pathelement location="${libraries}/email/javax.mail.jar"/>
<pathelement location="${libraries}/ftp/commons-logging-1.2.jar"/>
<pathelement location="${libraries}/ftp/commons-net-3.3.jar"/>
<pathelement location="${libraries}/ftp/commons-vfs2-2.0.jar"/>
<pathelement location="${libraries}/ftp/jsch-0.1.53.jar"/>
<fileset dir="${libraries}/aws/third-party" includes="**/*.jar"/>
<fileset dir="${libraries}/aws/lib" includes="**/*.jar"/>
</path>
<target name="clean">
<delete dir="${build}" failonerror="false"/>
<delete dir="${documentation}" failonerror="false"/>
</target>
<target name="init">
<tstamp>
<format property="today" pattern="yyyy.MM.dd"/>
<format property="now" pattern="HH:mm:ss z"/>
</tstamp>
<echo message="Time now ${now}"/>
<echo message="ant.java.version = 17" />
<mkdir dir="${build}"/>
<mkdir dir="${products}"/>
</target>
<target name="compile" depends="init">
<javac destdir="${build}" optimize="on"
source="17"
classpathref="classpath"
includeantruntime="false"
debug="true" debuglevel="lines,vars,source">
<src path="${java}"/>
<!-- <compilerarg value="-Xlint:unchecked"/> -->
<compilerarg line="--add-exports java.base/com.sun.crypto.provider=ALL-UNNAMED"/>
</javac>
</target>
<target name="jar" depends="compile">
<mkdir dir="${build}/CTP"/>
<jar jarfile="${build}/CTP/Launcher.jar">
<manifest>
<attribute name="Main-Class" value="org.rsna.launcher.Launcher"/>
<attribute name="Date" value="${today} at ${now}"/>
<attribute name="Java-Version" value="17"/>
<attribute name="Class-Path" value="libraries/util.jar libraries/log4j.jar libraries/aws/lib/aws-java-sdk-1.11.483-javadoc.jar libraries/aws/lib/aws-java-sdk-1.11.483-sources.jar libraries/aws/lib/aws-java-sdk-1.11.483.jar libraries/aws/third-party/lib/aspectjrt-1.8.2.jar libraries/aws/third-party/lib/aspectjweaver.jar libraries/aws/third-party/lib/aws-swf-build-tools-1.1.jar libraries/aws/third-party/lib/commons-codec-1.10.jar libraries/aws/third-party/lib/commons-logging-1.1.3.jar libraries/aws/third-party/lib/freemarker-2.3.9.jar libraries/aws/third-party/lib/httpclient-4.5.5.jar libraries/aws/third-party/lib/httpcore-4.4.9.jar libraries/aws/third-party/lib/ion-java-1.0.2.jar libraries/aws/third-party/lib/jackson-annotations-2.6.0.jar libraries/aws/third-party/lib/jackson-core-2.6.7.jar libraries/aws/third-party/lib/jackson-databind-2.6.7.2.jar libraries/aws/third-party/lib/jackson-dataformat-cbor-2.6.7.jar libraries/aws/third-party/lib/javax.mail-api-1.4.6.jar libraries/aws/third-party/lib/jmespath-java-1.11.483.jar libraries/aws/third-party/lib/joda-time-2.8.1.jar libraries/aws/third-party/lib/netty-buffer-4.1.17.Final.jar libraries/aws/third-party/lib/netty-codec-4.1.17.Final.jar libraries/aws/third-party/lib/netty-codec-http-4.1.17.Final.jar libraries/aws/third-party/lib/netty-common-4.1.17.Final.jar libraries/aws/third-party/lib/netty-handler-4.1.17.Final.jar libraries/aws/third-party/lib/netty-resolver-4.1.17.Final.jar libraries/aws/third-party/lib/netty-transport-4.1.17.Final.jar libraries/aws/third-party/lib/spring-beans-3.0.7.RELEASE.jar libraries/aws/third-party/lib/spring-context-3.0.7.RELEASE.jar libraries/aws/third-party/lib/spring-core-3.0.7.RELEASE.jar libraries/aws/third-party/lib/spring-test-3.0.7.RELEASE.jar" />
</manifest>
<fileset dir="${build}"
includes="${launcher}/**" />
</jar>
<jar jarfile="${build}/CTP/Runner.jar">
<manifest>
<attribute name="Main-Class" value="org.rsna.runner.Runner"/>
<attribute name="Date" value="${today} at ${now}"/>
<attribute name="Java-Version" value="17"/>
</manifest>
<fileset dir="${build}"
includes="${runner}/**" />
</jar>
<copy overwrite="true" todir="${build}">
<fileset dir="${resources}"/>
</copy>
<jar jarfile="${libraries}/CTP.jar">
<manifest>
<attribute name="Main-Class" value="org.rsna.ctp.ClinicalTrialProcessor"/>
<attribute name="Date" value="${today} at ${now}"/>
<attribute name="Java-Version" value="17"/>
<attribute name="Class-Path" value="util.jar log4j.jar"/>
</manifest>
<fileset dir="${build}"
includes="**"
excludes="${installer}/**, ${launcher}/**, ${runner}/** CTP/Launcher.jar CTP/Runner.jar" />
</jar>
</target>
<target name="installer" depends="jar">
<mkdir dir="${build}/CTP/libraries"/>
<mkdir dir="${build}/CTP/libraries/email"/>
<mkdir dir="${build}/config"/>
<copy overwrite="true" todir="${build}/CTP">
<fileset dir="${files}" includes="**"/>
</copy>
<copy overwrite="true" todir="${build}/CTP/libraries">
<fileset dir="${libraries}" includes="*.*" excludes="jai_imageio.jar"/>
</copy>
<copy overwrite="true" todir="${build}/CTP/libraries/email">
<fileset dir="${libraries}/email" includes="*.*"/>
</copy>
<copy overwrite="true" todir="${build}/CTP/libraries/aws">
<fileset dir="${libraries}/aws" includes="**/*.jar"/>
</copy>
<copy overwrite="true" todir="${build}/CTP/libraries/ftp">
<fileset dir="${libraries}/ftp" includes="*.*"/>
</copy>
<copy overwrite="true" todir="${build}/CTP/libraries/imageio">
<fileset dir="${libraries}/imageio" includes="*.*"/>
</copy>
<copy overwrite="true" todir="${build}/config">
<fileset dir="${config}" includes="*.*"/>
</copy>
<jar destfile="${products}/CTP-installer.jar">
<manifest>
<attribute name="Main-Class" value="org.rsna.installer.Installer"/>
<attribute name="Date" value="${today} at ${now}"/>
<attribute name="Java-Version" value="17"/>
<attribute name="Description" value="CTP for clinical trials"/>
</manifest>
<fileset dir="${build}"
includes="${installer}/Installer** CTP/** config/**"/>
</jar>
</target>
<target name="javadocs">
<mkdir dir="${documentation}"/>
<javadoc destdir="${documentation}" sourcepath="${java}" classpathref="classpath"
doctitle="${title}" windowtitle="${title}" bottom="${copyright}">
<package name="org.*"/>
</javadoc>
</target>
<target name="all" depends="clean, installer, javadocs">
<tstamp>
<format property="end" pattern="HH:mm:ss"/>
</tstamp>
<echo message="Time now ${end}"/>
</target>
</project>

.gitlab-ci.yml

stages:
- deploy
default:
before_script:
- sudo apt update
- sudo apt install -y software-properties-common
- sudo apt-get install ca-certificates
- sudo add-apt-repository --yes "deb https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ bionic main"
- sudo apt-get update -qq && sudo apt-get install -y adoptopenjdk-17-hotspot latex209-bin texlive-latex-base texlive-latex-extra ant
- ant all -f src/build.xml
- sudo apt-get update -qq && sudo apt-get install -y latex209-bin texlive-latex-base texlive-latex-extra ant
- ant all -f src/build.xml
deploy_Default:
stage: deploy
script:
- sh -x doc.sh "$CTP_NAME" "$(cat CTP_VERSION)"
- sh -x deploy.sh "$CTP_NAME" "$(cat CTP_VERSION)" "$PROFILE_VERSION" "$PROFILE_NAME"
artifacts:
paths:
- "${CTP_NAME}_$(cat CTP_VERSION).zip"
only:
- master
- tags
- ptname_mapping

Answer

According to the information provided in the comments, you have Java 14.0.1 on your GitLab runner. Since this Java version is used to launch ant and its tasks, it cannot compile code with a “17” target version.

To make a long story short, you’ll need a newer Java version on your runner.

The simplest way of doing this is probably by using a pre-built image that contains it:

deploy_Default:
stage: deploy
image: openjdk:17
script:
- sh -x doc.sh "$CTP_NAME" "$(cat CTP_VERSION)"
- sh -x deploy.sh "$CTP_NAME" "$(cat CTP_VERSION)" "$PROFILE_VERSION" "$PROFILE_NAME"

If that’s not a possibility, you could explicitly install it in the before script stage:

default:
before_script:
- wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | sudo apt-key add -
- sudo add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/
- sudo apt-get update -qq && sudo apt-get install -y adoptopenjdk-17-hotspot latex209-bin texlive-latex-base texlive-latex-extra ant
- ant all -f src/build.xml