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

Add support for Java 9 to Groovy-Eclipse Maven plugin (aka batch compiler) #265

Closed
johnpoth opened this issue Feb 15, 2017 · 8 comments
Closed
Assignees

Comments

@johnpoth
Copy link

I'm using the following configuration with java 9 build 156

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <source>8</source>
          <target>8</target>
          <fork>true</fork>-
          <compilerArgs>
            <arg>-J--add-modules</arg>  // add java.xml module!
            <arg>-Jjava.xml</arg>
          </compilerArgs>
        </configuration>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-compiler</artifactId>
            <version>2.9.2-01</version>
            <exclusions>
              <exclusion>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-eclipse-batch</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-eclipse-batch</artifactId>
            <version>2.4.3-01</version>
          </dependency>
        </dependencies>
      </plugin>

But I still get the error

TransformerException cannot be resolved to a type

Where javax/xml/transform/TransformerException is a class present in the java 9 module called java.xml. The above works with the maven compiler plugin.

Am I doing something wrong or is java 9 not supported yet?

Thanks!

@eric-milles
Copy link
Member

I'm not sure where Java 9 support begins and ends exactly. You may need to bootstrap modules to the classpath for this to work with the 2.4.3 compiler. In development we have the 2.4.8 compiler in place. Not sure if it has better support. We'd need to get a release of it so you could reference it in your POM.

@eric-milles eric-milles changed the title Groovy Eclipse Maven plugin java 9 support Add support for Java 9 to Groovy-Eclipse Maven plugin (aka batch compiler) Sep 7, 2017
@eric-milles eric-milles self-assigned this Oct 1, 2017
@eric-milles
Copy link
Member

As soon as Eclipse Oxygen 4.7.1a is released, I will publish a Java 9 compatible batch compiler.

@ispringer
Copy link

Eclipse Oxygen 4.7.1a has been released.

https://www.eclipse.org/eclipse/news/4.7.1a/

@eric-milles
Copy link
Member

Batch compiler 2.4.12-05 is available from bintray. There are a couple hitches that require a few changes to your POM. If you follow these instructions to get to a stable Java 8 build, you can make the following changes to get Java 9 to go. Be sure to adjust any existing Maven run configurations to use a Java 9 execution environment.

  <properties>
    <maven.compiler.fork>false</maven.compiler.fork>
    <maven.compiler.source>9</maven.compiler.source>
    <maven.compiler.target>9</maven.compiler.target>
  </properties>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerId>groovy-eclipse-compiler</compilerId>
          <compilerArgument>${maven.compiler.source}</compilerArgument>
        </configuration>
        ...

Until this bug is resolved, the compliance level must be passed in as an argument, which is what <compilerArgument>${maven.compiler.source}</compilerArgument> accomplishes.

If you want to run with a forked compiler, I believe the java.compiler module must be added to the forked VM. I haven't worked out exactly what to set in the POM to make this work. I will probably look to fix this in the compiler adapter at some point.

You should be able to add modules to the compilation modulepath with <compilerArgument>--add-modules=ALL-SYSTEM</compilerArgument> or whatever. Supported compiler arguments are listed here. Although it does not appear to have been updated for the Java 9 changes yet.

@ispringer
Copy link

Thank you!

It seems like there may be a regression in this new version of the compiler. I get a compiler error that I didn't previously get, which seems invalid.

I have a Groovy class that looks like this:

package com.foo

class TestUserAgents {
    static final String[] DESKTOP_AGENTS = ["blah"]
}

which I then static import into another Groovy class as follows:

import static com.foo.TestUserAgents.DESKTOP_AGENTS

And I am getting the following compile error:

	import static com.foo.TestUserAgents.DESKTOP_AGENTS
	              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The field TestUserAgents.com.foo.TestUserAgents.DESKTOP_AGENTS is not visible

Adding the "public" modifier to 'static final String[] DESKTOP_AGENTS = ["blah"]' fixes the error, but it doesn't seem like I should have to do that...

Any idea what might be going on?

Note, I'm using JDK8, not JDK9.

@eric-milles
Copy link
Member

The issue you mention was raised as #336. Without the public modifier, Groovy creates a private field of the given name and a public accessor method. The import checking occurs against the field and not the accessor. If I were to disable the checking that is at play here, some other added checks like null annotations would also go away. That is why I recommend the public modifier as you mentioned and marked the issue as Won't Fix.

@Zoden
Copy link

Zoden commented Oct 22, 2017

Hi!

I'm trying to use 2.4.12-05 now, but I've got such an error:

java.lang.NullPointerException at org.eclipse.jdt.internal.compiler.lookup.Scope.findDirectMemberType(Scope.java:1250)

It seems to be fixed in this issues:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=520658
https://bugs.eclipse.org/bugs/show_bug.cgi?id=486013

4.8M2 is out some days ago, according to this plan

My question is - is there any place to get snapshot build of batch compiler with all latest changes?

I've tried this https://build.spring.io/browse/GRECLIPSE-GE47 but without any luck. Maybe I'm looking in a wrong place?

Thank you!

@eric-milles
Copy link
Member

Eclipse 4.8M2 does not contain the Java 9 support. I think M3 will have it. If you don't need Java 9 support, 2.4.12-04 should work better.

If you wish to create an updated compiler artifact, you can clone this repository and get a zip of JDT Core at any commit you like. When you diff the org.eclipse.jdt.core project between the two, you would move in any changes that are not marked as // GROOVY ... in this repo.

Then the steps to create a new batch compiler are here. The batch compiler is not built as part of the CI builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants