You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@netbeans.apache.org by Thomas Kellerer <sh...@gmx.net> on 2017/12/14 11:26:21 UTC

Maven project with a mix of Java 9 and Java 8

Hello,

I am trying to open/use a Maven based project that uses a mix of Java 9 and Java 8 features. 

I am using the current NetBeans 9 nightly build (from http://bits.netbeans.org/download/trunk/nightly/latest/zip/) 

The pom.xml looks like this:

<build>
  <sourceDirectory>src/main/java</sourceDirectory>
  <plugins>
    <plugin>
      <artifactId>maven-compiler-plugin</artifactId>
      <version>3.7.0</version>
      <configuration>
        <jdkToolchain>
          <version>9</version>
        </jdkToolchain>
        <release>8</release>
        <encoding>${project.build.sourceEncoding}</encoding>
      </configuration>
      <executions>
        <execution>
          <id>default-compile</id>
          <configuration>
            <release>9</release>
          </configuration>
        </execution>
        <execution>
          <id>base-compile</id>
          <goals>
            <goal>compile</goal>
          </goals>
          <configuration>
            <excludes>
              <exclude>module-info.java</exclude>
            </excludes>
          </configuration>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>

The idea is to compile the project into a Java 8 compatible JAR file while being able to use the Java 9 module system in environments that use Java 9 (a "multi-release" jar). This works fine when using Maven to build the project, but I can't get NetBeans to properly use that project without marking everything as erroneous.

If I open it "as is" with "JDK 9" as the default JDK, but the source level set to Java 8, the editor complains that none of the dependencies can be imported. 
For example a simple "import java.sql.Connection;" results in an "error" inside the editor. 

If I switch the Java Platform to Java 8 the same thing happens. It seems that NetBeans tries to derive the classpath from module-info.java regardless of the source level configured in Maven. 

The only way I get this project to properly work in NetBeans is to select JDK 9 as Java platform *and* switch the source level to Java 9 in the project properties. This however changes the pom.xml and inserts 

   <source>9</source>
   <target>9</target>

into the <configuration> section. 

However, this is not really an option because for one I have to change the pom.xml which is versioned in git and should not contain that part (and I need to pay attention that I don't accidentally  commit "my" version of the pom. And on the other hand I have no protection against accidentally using Java 9 features.

So is there a way I can convince NetBeans to use the Maven dependencies (and not the module-info.java) if the project is configured to use Java 8 level?

It seems that neither Eclipse nor InteliJ have problems opening and using that Maven project (Sadly I am the only one using NetBeans in the team, so I can't really expect much help from there)


Thanks
Thomas







Re: Maven project with a mix of Java 9 and Java 8

Posted by Geertjan Wielenga <ge...@googlemail.com>.
I don't know. I'd advise to file an issue so that someone can take a look
at it.

Gj

On Thu, Dec 14, 2017 at 1:09 PM, Thomas Kellerer <sh...@gmx.net> wrote:

> So does that mean this is supposed to work with NetBeans 9?
>
> And if it is, what would be the correct way to configure it?
>
>
> Geertjan Wielenga schrieb am 14.12.2017 um 13:07:
> > Then you should file an issue with step by step instructions how to
> reproduce the problem: https://issues.apache.org/jira/projects/NETBEANS
> >
> > Gj
> >
> > On Thu, Dec 14, 2017 at 1:05 PM, Thomas Kellerer <shammat@gmx.net
> <ma...@gmx.net>> wrote:
> >
> >     Geertjan Wielenga schrieb am 14.12.2017 um 12:46:
> >     > On Thu, Dec 14, 2017 at 12:26 PM, Thomas Kellerer <shammat@gmx.net
> <ma...@gmx.net> <mailto:shammat@gmx.net <ma...@gmx.net>>>
> wrote:
> >     >
> >     >     Hello,
> >     >
> >     >     I am trying to open/use a Maven based project that uses a mix
> of Java 9 and Java 8 features.
> >     >
> >     >     I am using the current NetBeans 9 nightly build (from
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/> <
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/>>)
> >     >
> >     >
> >     > That is not Apache NetBeans.
> >     >
> >     > Apache NetBeans is here: github.com/apache/incubator-netbeans <
> http://github.com/apache/incubator-netbeans> <http://github.com/apache/
> incubator-netbeans <http://github.com/apache/incubator-netbeans>>
> >     >
> >     > Binaries available here: builds.apache.org/job/
> incubator-netbeans-linux <http://builds.apache.org/job/
> incubator-netbeans-linux> <http://builds.apache.org/job/
> incubator-netbeans-linux <http://builds.apache.org/job/
> incubator-netbeans-linux>>
> >     >
> >
> >     That version behaves exactly the same way.
> >
> >
> >
>

Re: Maven project with a mix of Java 9 and Java 8

Posted by Thomas Kellerer <sh...@gmx.net>.
So does that mean this is supposed to work with NetBeans 9? 

And if it is, what would be the correct way to configure it? 


Geertjan Wielenga schrieb am 14.12.2017 um 13:07:
> Then you should file an issue with step by step instructions how to reproduce the problem: https://issues.apache.org/jira/projects/NETBEANS
> 
> Gj
> 
> On Thu, Dec 14, 2017 at 1:05 PM, Thomas Kellerer <shammat@gmx.net <ma...@gmx.net>> wrote:
> 
>     Geertjan Wielenga schrieb am 14.12.2017 um 12:46:
>     > On Thu, Dec 14, 2017 at 12:26 PM, Thomas Kellerer <shammat@gmx.net <ma...@gmx.net> <mailto:shammat@gmx.net <ma...@gmx.net>>> wrote:
>     >
>     >     Hello,
>     >
>     >     I am trying to open/use a Maven based project that uses a mix of Java 9 and Java 8 features.
>     >
>     >     I am using the current NetBeans 9 nightly build (from http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <http://bits.netbeans.org/download/trunk/nightly/latest/zip/> <http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <http://bits.netbeans.org/download/trunk/nightly/latest/zip/>>)
>     >
>     >
>     > That is not Apache NetBeans.
>     >
>     > Apache NetBeans is here: github.com/apache/incubator-netbeans <http://github.com/apache/incubator-netbeans> <http://github.com/apache/incubator-netbeans <http://github.com/apache/incubator-netbeans>>
>     >
>     > Binaries available here: builds.apache.org/job/incubator-netbeans-linux <http://builds.apache.org/job/incubator-netbeans-linux> <http://builds.apache.org/job/incubator-netbeans-linux <http://builds.apache.org/job/incubator-netbeans-linux>>
>     >
> 
>     That version behaves exactly the same way.
> 
> 
> 

Re: Maven project with a mix of Java 9 and Java 8

Posted by Geertjan Wielenga <ge...@googlemail.com>.
Then you should file an issue with step by step instructions how to
reproduce the problem: https://issues.apache.org/jira/projects/NETBEANS

Gj

On Thu, Dec 14, 2017 at 1:05 PM, Thomas Kellerer <sh...@gmx.net> wrote:

> Geertjan Wielenga schrieb am 14.12.2017 um 12:46:
> > On Thu, Dec 14, 2017 at 12:26 PM, Thomas Kellerer <shammat@gmx.net
> <ma...@gmx.net>> wrote:
> >
> >     Hello,
> >
> >     I am trying to open/use a Maven based project that uses a mix of
> Java 9 and Java 8 features.
> >
> >     I am using the current NetBeans 9 nightly build (from
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/>)
> >
> >
> > That is not Apache NetBeans.
> >
> > Apache NetBeans is here: github.com/apache/incubator-netbeans <
> http://github.com/apache/incubator-netbeans>
> >
> > Binaries available here: builds.apache.org/job/incubator-netbeans-linux
> <http://builds.apache.org/job/incubator-netbeans-linux>
> >
>
> That version behaves exactly the same way.
>
>
>

Re: Maven project with a mix of Java 9 and Java 8

Posted by Thomas Kellerer <sh...@gmx.net>.
Geertjan Wielenga schrieb am 14.12.2017 um 12:46:
> On Thu, Dec 14, 2017 at 12:26 PM, Thomas Kellerer <shammat@gmx.net <ma...@gmx.net>> wrote:
> 
>     Hello,
> 
>     I am trying to open/use a Maven based project that uses a mix of Java 9 and Java 8 features.
> 
>     I am using the current NetBeans 9 nightly build (from http://bits.netbeans.org/download/trunk/nightly/latest/zip/ <http://bits.netbeans.org/download/trunk/nightly/latest/zip/>)
> 
> 
> That is not Apache NetBeans.
> 
> Apache NetBeans is here: github.com/apache/incubator-netbeans <http://github.com/apache/incubator-netbeans>
> 
> Binaries available here: builds.apache.org/job/incubator-netbeans-linux <http://builds.apache.org/job/incubator-netbeans-linux>
> 

That version behaves exactly the same way. 



Re: Maven project with a mix of Java 9 and Java 8

Posted by Geertjan Wielenga <ge...@googlemail.com>.
On Thu, Dec 14, 2017 at 12:26 PM, Thomas Kellerer <sh...@gmx.net> wrote:

> Hello,
>
> I am trying to open/use a Maven based project that uses a mix of Java 9
> and Java 8 features.
>
> I am using the current NetBeans 9 nightly build (from
> http://bits.netbeans.org/download/trunk/nightly/latest/zip/)
>


That is not Apache NetBeans.

Apache NetBeans is here: github.com/apache/incubator-netbeans

Binaries available here: builds.apache.org/job/incubator-netbeans-linux

Gj





>
> The pom.xml looks like this:
>
> <build>
>   <sourceDirectory>src/main/java</sourceDirectory>
>   <plugins>
>     <plugin>
>       <artifactId>maven-compiler-plugin</artifactId>
>       <version>3.7.0</version>
>       <configuration>
>         <jdkToolchain>
>           <version>9</version>
>         </jdkToolchain>
>         <release>8</release>
>         <encoding>${project.build.sourceEncoding}</encoding>
>       </configuration>
>       <executions>
>         <execution>
>           <id>default-compile</id>
>           <configuration>
>             <release>9</release>
>           </configuration>
>         </execution>
>         <execution>
>           <id>base-compile</id>
>           <goals>
>             <goal>compile</goal>
>           </goals>
>           <configuration>
>             <excludes>
>               <exclude>module-info.java</exclude>
>             </excludes>
>           </configuration>
>         </execution>
>       </executions>
>     </plugin>
>   </plugins>
> </build>
>
> The idea is to compile the project into a Java 8 compatible JAR file while
> being able to use the Java 9 module system in environments that use Java 9
> (a "multi-release" jar). This works fine when using Maven to build the
> project, but I can't get NetBeans to properly use that project without
> marking everything as erroneous.
>
> If I open it "as is" with "JDK 9" as the default JDK, but the source level
> set to Java 8, the editor complains that none of the dependencies can be
> imported.
> For example a simple "import java.sql.Connection;" results in an "error"
> inside the editor.
>
> If I switch the Java Platform to Java 8 the same thing happens. It seems
> that NetBeans tries to derive the classpath from module-info.java
> regardless of the source level configured in Maven.
>
> The only way I get this project to properly work in NetBeans is to select
> JDK 9 as Java platform *and* switch the source level to Java 9 in the
> project properties. This however changes the pom.xml and inserts
>
>    <source>9</source>
>    <target>9</target>
>
> into the <configuration> section.
>
> However, this is not really an option because for one I have to change the
> pom.xml which is versioned in git and should not contain that part (and I
> need to pay attention that I don't accidentally  commit "my" version of the
> pom. And on the other hand I have no protection against accidentally using
> Java 9 features.
>
> So is there a way I can convince NetBeans to use the Maven dependencies
> (and not the module-info.java) if the project is configured to use Java 8
> level?
>
> It seems that neither Eclipse nor InteliJ have problems opening and using
> that Maven project (Sadly I am the only one using NetBeans in the team, so
> I can't really expect much help from there)
>
>
> Thanks
> Thomas
>
>
>
>
>
>
>