Search code examples
tekton

Tekton - maven task - cannot compile with JDK 17


Building a project with the Tekton standard "maven" Task works fine for JDK8 and JDK11.

When changing to another JDK17 project, I get this message:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project quotes: Fatal error compiling: error: invalid target release: 17 -> [Help 1]

The default maven plugin version was 3.10.1.

How can I build with the modern JDK17 in Tekton task Maven?

In the pom.xml I have all settings (and even more then strictly necessary) to ask maven to compile with JDK17:

<properties>
  <java.version>17</java.version>
  <maven.compiler.target>17</maven.compiler.target>
  <maven.compiler.source>17</maven.compiler.source>
</properties>

Optionally I even added the superfluous statements:

<build>
    <plugins>
        ...
        <plugin>
             <groupId>org.apache.maven.plugins</groupId>
             <artifactId>maven-compiler-plugin</artifactId>
             <version>3.8.1</version>    
             <configuration>
                <source>17</source>
                <target>17</target>
             </configuration>
        </plugin>
    </plugins>
</build>

Solution

  • The standard (Tekton Hub) maven task has an optional parameter to set a specific maven-build image.

    Just add in the Pipeline the parameter 'MAVEN_IMAGE' as shown below:

    - name: maven
      taskRef:
        name: maven
      runAfter:
        - fetch-repository
      params:
        - name: GOALS
          value:
            - -Dmaven.repo.local=$(workspaces.maven-settings.path)
            - package
        - name: MAVEN_IMAGE
          value: maven:3-eclipse-temurin-17-alpine