Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is "<release>" element on "<configuration>" for the "maven-compiler-plugin" in a JavaFX app

I used the org.openjfx:javafx-archetype-simple Maven archetype to start my first JavaFX project.

The resulting POM:

<project xmlns = "http://maven.apache.org/POM/4.0.0"
         xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example.invoicing</groupId>
    <artifactId>Invoicer</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.openjfx</groupId>
            <artifactId>javafx-controls</artifactId>
            <version>14</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <release>14</release>  🡄 ???
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>com.example.invoicing.App</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

➥ What is the purpose of the <release>14</release> line in <configuration> for the plugin <artifactId>maven-compiler-plugin</artifactId>?

I found this documentation for the Maven Compiler Plugin, Compiling Your Java Sources. But it only mentions <!-- put your configurations here -->. So I do not know anything about specific configuration options here.

Is <release>14</release> the version of Java being used to compile? Is it the version of OpenJFX? Something else?

I tried using 28 arbitrarily. Doing a Maven > install threw this error with an unhelpful error message with no clue as to a release of what product:

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

like image 560
Basil Bourque Avatar asked Jan 26 '23 05:01

Basil Bourque


1 Answers

The release flag is equivalent to specifying the source and target of the same value for the compiler plugin. It supports the -release argument for the Java compiler since Java-9.

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

Note: For the same reason, you can get rid of the redundant properties declared as

<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>

Further: What is the --release flag in the Java 9 compiler? | The -release flag in javac was introduced to Compile for Older Platform Versions.


To complete the answer over the part where you've tried the version value as 28. While using Maven version -

Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T00:30:29+05:30)

The error message reads very clearly what it should (if you could share the complete logs in the question)

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project forty-bits-of-java: 
Fatal error compiling: error: release version 28 not supported 
like image 126
Naman Avatar answered Jan 27 '23 18:01

Naman