Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java 8 Maven Projects fail with 2.0.1 Build Snapshot (invalid flag: --release) #320

Closed
4 tasks done
JasonTypesCodes opened this issue Jul 9, 2020 · 3 comments · Fixed by #323
Closed
4 tasks done
Assignees
Labels
type: bug Something isn't working

Comments

@JasonTypesCodes
Copy link
Contributor

Description

A new project created with 2.0.1 Build Snapshot for Java 8 with Maven will not build. I observed this when debugging failing GitHub Actions for #319

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Steps to Reproduce

  1. Create a new app with Java 8, and Maven Here's one
  2. Using JDK 8, try to build the application

Expected Behaviour

The application should build

Actual Behaviour

The application does not build:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------< com.example:demo >--------------------------
[INFO] Building demo 0.1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/schindlerj/src/temp/mn2-mvn-jdk8/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.941 s
[INFO] Finished at: 2020-07-08T23:21:18-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo: Fatal error compiling: invalid flag: --release -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Environment Information

  • Operating System: Fedora Linux Workstation 31
  • Micronaut Version: 2.0.1.BUILD-SNAPSHOT
  • JDK Version: OpenJDK Runtime Environment (build 1.8.0_252-b09)

Example Application

https://github.com/JasonTypesCodes/mn2-mvn-jdk8

@JasonTypesCodes
Copy link
Contributor Author

I believe what is happening, is that the micronaut-parent pom includes <maven.compiler.release>${jdk.version}</maven.compiler.release> however the release flag is only supported in JDK 9 and higher.

Adding <maven.compiler.release/> to the application pom seems to unset the property and the compiler succeeds with JDK 8.

@ilopmar ilopmar added the type: bug Something isn't working label Jul 9, 2020
@JasonTypesCodes
Copy link
Contributor Author

My earlier comment is only partially correct. Unsetting maven.compiler.release fixes compile but testCompile still fails with

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project something: Execution default-testCompile of goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile failed: For input string: ""

This is because of a call to Integer.valueOf here: https://github.com/apache/maven-compiler-plugin/blob/maven-compiler-plugin-3.8.1/src/main/java/org/apache/maven/plugin/compiler/TestCompilerMojo.java#L305

An issue (https://issues.apache.org/jira/browse/MCOMPILER-339) exists in the Maven Compiler Plugin Jira requesting that Maven just ignore release when the JDK being used is < 9.

A comment there suggests:

It is extremely dangerous to ignore the release flag. What should work for you is a profile activated by JDK:

    <profile>
      <id>javac-release</id>
      <activation>
        <jdk>[11,)</jdk>
      </activation>
      <properties>
        <maven.compiler.release>8</maven.compiler.release>
      </properties>
    </profile>

@JasonTypesCodes
Copy link
Contributor Author

It looks like all Java 8 builds are failing. They fail in JDK 8 due to the release flag error here and in newer versions because the parent pom is setting the release flag to 1.8 which isn't supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
2 participants