2

Recently I have upgraded spring batch project from java 8 to 11.

It works fine locally, and I decided to push to the Jenkins, but I get the following error.

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project bandwidth: 

Fatal error compiling: invalid flag: --release -> [Help 1]

What should be the cause, and how can I solve it?

Old setting: java 8 in pom

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

    <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
    <org.springframework.batch>2.1.9.RELEASE</org.springframework.batch>
    <org.slf4j-version>1.6.2</org.slf4j-version>
</properties>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>iso-8859-1</encoding>
    </configuration>
</plugin>

New setting: java 11 in pom

<properties>
        <java.version>11</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <org.springframework-version>3.1.1.RELEASE</org.springframework-version>
        <org.springframework.batch>2.1.9.RELEASE</org.springframework.batch>
        <org.slf4j-version>1.6.2</org.slf4j-version>
</properties>
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
     <version>3.8.1</version>
     <configuration>
            <release>11</release>
            <encoding>iso-8859-1</encoding>
    </configuration>
</plugin>
Naman
  • 27,789
  • 26
  • 218
  • 353
itro
  • 7,006
  • 27
  • 78
  • 121

1 Answers1

1

The problem was with the Jenkins setting which fallback on default system JDK.

I did add the following and corrected Jenkins pointing to JDK 11.

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

Thanks to @naman putting me to the right direction.

Azhagu Surya
  • 132
  • 1
  • 1
  • 17
itro
  • 7,006
  • 27
  • 78
  • 121
  • 2
    are you sure your Jenkins is running with JDK 11(after removing those configurations, you might just be falling back to the default Java version resolved by Maven)? Just try executing the `mvn` command with `-X` and see by yourself which Java version does it use to execute the Maven command. The property to use could be `11`. – Naman May 20 '21 at 14:21