Tirrel
Tirrel

Reputation: 778

Impossible to compile using maven-compiler-plugin with Java higher than 1.8

I have a NetBeans maven-based project that I want to switch from Java 1.8 to 12 but I can't compile it.

After many attempts, I have decided to start from the beginning, and create a very simple project to understand how to do this change.

Well, I have tried and I can't compile the simple project either.

Could someone explain what I am doing wrong?

Preamble

NetBeans: 10.0

JAVA_HOME: C:\Program Files\Java\jdk-12 (I have tried also 9, 10, 11)

Maven: Console output of Maven

Project creation

  1. Create Project with a Window (first TopComponent)

Netbeans display window

  1. I changed the JDK version from 11 (default in NetBeans 10.0) to 12

Project properties in NetBeans

  1. This is the autogenerated POM with and the javax.annotation-api Dependency

    <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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>it.prj</groupId>
        <artifactId>Project-parent</artifactId>
        <version>2.9</version>
    </parent>
    <artifactId>Project-source</artifactId>
    <packaging>nbm</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>nbm-maven-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <useOSGiDependencies>true</useOSGiDependencies>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <useDefaultManifestFile>true</useDefaultManifestFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-netbeans-api-annotations-common</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-openide-windows</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-openide-util</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-openide-util-ui</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-openide-util-lookup</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-openide-awt</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans.api</groupId>
            <artifactId>org-netbeans-modules-settings</artifactId>
            <version>${netbeans.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
            <type>jar</type>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    

  2. Then I start the Clean & Build > SUCCESS

  3. I changed the Java version from 1.7 to 12

Changing java version in properties

This add the related Plugin to the POM

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>12</source>
                <target>12</target>
            </configuration>
        </plugin>
  1. Update the version field, so it becomes:

       <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>12</source>
                <target>12</target>
            </configuration>
        </plugin>
    
  2. Then I restart the Clean & Build > FAILED

    cd D:\Project\Project-source; "JAVA_HOME=C:\\Program Files\\Java\\jdk-12" "M2_HOME=C:\\Program Files\\apache-maven-3.6.0" cmd /c "\"\"C:\\Program Files\\apache-maven-3.6.0\\bin\\mvn.cmd\" -Dmaven.ext.class.path=\"C:\\Program Files\\Netbeans 10.0\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 clean install\""
    

    Building Project-source 2.9

    --- maven-clean-plugin:2.5:clean (default-clean) @ Project-source ---

Deleting D:\Project\Project-source\target

--- maven-resources-plugin:3.1.0:resources (default-resources) @ Project-source ---

Using 'UTF-8' encoding to copy filtered resources.
Copying 1 resource

--- maven-compiler-plugin:3.8.0:compile (default-compile) @ Project-source ---
Changes detected - recompiling the module!
Compiling 1 source file to D:\Project\Project-source\target\classes

--- nbm-maven-plugin:4.1:manifest (default-manifest) @ Project-source ---
NBM Plugin generates manifest
Adding OSGi bundle dependency - javax.annotation:javax.annotation-api
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest (default-manifest) on project Project-source: 
Execution default-manifest of goal org.codehaus.mojo:nbm-maven-plugin:4.1:manifest failed.: IllegalArgumentException 

EDIT

  1. i have tried to remove nbm-maven-plugin as suggested but this change the structure of Project and i don't know how to reinclude this module

enter image description here

Upvotes: 2

Views: 1653

Answers (2)

Jacob Tuz
Jacob Tuz

Reputation: 196

Please use the 4.2 version like this:

<groupId>org.apache.netbeans.utilities</groupId>
<artifactId>nbm-maven-plugin</artifactId>
<version>4.2</version>

replacing any references to:

 <groupId>org.codehaus.mojo</groupId>
 <artifactId>nbm-maven-plugin</artifactId>

jar file generated by jdk>8 cannot be parsed by older version of the plugin.

Upvotes: 4

Karol Dowbecki
Karol Dowbecki

Reputation: 44942

In your example nbm-maven-plugin fails but the compilation process is fine.

Temporarily remove nbm-maven-plugin from your build and see if Maven can build without it. Perhaps you can skip this plugin altogether as it seems specific only to NetBeans IDE.

Upvotes: 2

Related Questions