Gitlab ant.java.version 是 11 但我想使用另一个版本构建项目

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

所以我正在使用 gitlab,我有一个 java 项目,该项目是使用 .gitlab-ci-yml 文件在 gitlab VM 上构建的。

我遇到这个问题,我们必须更改项目构建的 java 版本(当前 java 11)。

所以在 build.xml 中添加: <echo message="ant.java.version = ${ant.java.version}" /> 将打印 11.

我试图在 javacsourcetarget 中改变它的 specifying 但如果 target 不是 specified,它不会使用另一个 java 版本构建它,如果它是 specified,它将 return 一个错误:

同样使用 <property name="ant.build.javac.target" value="17" /> 将 return 同样的错误。
所以我不确定是否基本上将我自己的 ant 工具和 java 版本添加到包中并强制它使用那个是否有效,我不知道该怎么做。

这是 build.xml 文件和 .gitlab-ci.yml

更新.gitlab-ci.yml 已更新。现在错误似乎如下,具有以下 .gilab-ci.yml 文件: 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

根据评论中提供的信息,您的 GitLab runner 上有 Java 14.0.1。由于此 Java 版本用于启动 ant 及其任务,因此无法使用“17”目标版本编译代码。

长话短说,您的跑步者需要更新的 Java 版本。

执行此操作的最简单方法可能是使用包含它的预构建映像:

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"

如果这不可能,您可以在 before 脚本阶段显式安装它:

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