kelemen / netbeans-gradle-project

This project is a NetBeans plugin able to open Gradle based Java projects. The implementation is based on Geertjan Wielenga's plugin.
172 stars 57 forks source link

[JDK9] Upgrade gradle-tooling-api to 4.2.1 for compatibility with Java 9.0.1 #364

Closed mossroy closed 6 years ago

mossroy commented 6 years ago

With current version 2.0.0.1 of the plugin (using version 4.0.1 of gradle-tooling-api) and Java 9.0.1 (from openjdk or oracle), an exception is thrown when opening a gradle project : "Exception while executing a Gradle command" :

java.lang.IllegalArgumentException: Could not determine java version from '9.0.1'.
at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70)

It seems to come from the fact that JavaVersion class fails to find the java main version (7, 8, 9, etc), because version string "9.0.1" is not handled by the regexp patterns. This seems to be fixed in version 4.2.1 of gradle, probably by https://github.com/gradle/gradle/commit/27127bed9b655e41857aee3528275c4b8a3dc3da

Workaround: replace gradle-tooling-api-4.0.1.jar in ~/.netbeans/version/modules/ext by the jar downloaded from https://repo.gradle.org/gradle/libs-releases-local/org/gradle/gradle-tooling-api/4.2.1/gradle-tooling-api-4.2.1.jar (and rename it to gradle-tooling-api-4.0.1.jar)

kelemen commented 6 years ago

You will have to use the development build of NB for Java 9 support and build the nb9 branch of this plugin. Sadly, I can't easily update the dependencies in the version compatible with NB 8.2 because there are some incompatibilities between this plugin and newer versions of the tooling API of Gradle. I have updated the dependencies for NB 9 because that is a point where I can get away with an incompatible change.

That said, there are some problems with Java 9 integration what I still not fixed fully (only have some local changes partially solving the issue with modules).

thuryn commented 6 years ago

The plugin built from nb9 branch does not work for me on the today's incubator-netbeans-release. It throws an exception when I try to activate module.

kelemen commented 6 years ago

I will check myself and try to fix this tonight.

kelemen commented 6 years ago

It seems that Groovy is not bundled in that build by default. I'm not sure how to install Groovy alone but if you install Groovy and Grails plugin, it will install it.

kelemen commented 6 years ago

I have played with this a little and found that if you are using the dev version, you will probably have to uninstall / reinstall the plugin because Groovy is not bundled but since this plugin was installed into the user directory, NB assumes that it has everything already installed (but this is not true for Groovy).

thuryn commented 6 years ago

Thank you for fast response. When I've installed groovy gradle plugin is back again. But I have still the problem with java version. When I run the gradle task by gradlew manually it works fine. But NB still throws exception: Stack trace: java.lang.IllegalArgumentException: Could not determine java version from '9.0.1'. at org.gradle.api.JavaVersion.toVersion(JavaVersion.java:70) at org.gradle.api.JavaVersion.current(JavaVersion.java:80) at org.gradle.internal.jvm.UnsupportedJavaRuntimeException.assertUsingVersion(UnsupportedJavaRuntimeException.java:29) at org.gradle.tooling.internal.consumer.ConnectorServices.checkJavaVersion(ConnectorServices.java:57) at org.gradle.tooling.internal.consumer.ConnectorServices.createConnector(ConnectorServices.java:35) at org.gradle.tooling.GradleConnector.newConnector(GradleConnector.java:85) at org.netbeans.gradle.project.model.GradleConnectorRef.open(GradleConnectorRef.java:43) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.createGradleConnectorRef(DefaultGradleModelLoader.java:133) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.createGradleConnector(DefaultGradleModelLoader.java:129) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.loadModelWithProgress(DefaultGradleModelLoader.java:512) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.fixProjectLoadKeyWithRootProject(DefaultGradleModelLoader.java:338) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.fixProjectLoadKey(DefaultGradleModelLoader.java:293) at org.netbeans.gradle.project.model.DefaultGradleModelLoader.lambda$fetchModelWithoutPersistentCache$4(DefaultGradleModelLoader.java:389) at org.netbeans.gradle.project.tasks.GradleDaemonManager.runNonBlockingGradleTask(GradleDaemonManager.java:32) at org.netbeans.gradle.project.tasks.GradleDaemonManager.lambda$submitGradleTask$1(GradleDaemonManager.java:117) at org.jtrim2.executor.TaskExecutor.lambda$execute$0(TaskExecutor.java:94) at org.jtrim2.executor.CancelableTasks.complete(CancelableTasks.java:133) at org.jtrim2.executor.AbstractTaskExecutor$SubmittedTask.execute(AbstractTaskExecutor.java:112) at org.jtrim2.executor.SingleThreadedExecutor$QueuedItem.runTask(SingleThreadedExecutor.java:858) at org.jtrim2.executor.SingleThreadedExecutor$QueuedItem.access$900(SingleThreadedExecutor.java:844) at org.jtrim2.executor.SingleThreadedExecutor$Impl$Worker.executeTask(SingleThreadedExecutor.java:762) at org.jtrim2.executor.SingleThreadedExecutor$Impl$Worker.processQueue(SingleThreadedExecutor.java:773) at org.jtrim2.executor.SingleThreadedExecutor$Impl$Worker.run(SingleThreadedExecutor.java:807) at org.jtrim2.executor.SingleThreadedExecutor$Impl.lambda$createOwnedWorkerThread$0(SingleThreadedExecutor.java:430) at java.base/java.lang.Thread.run(Thread.java:844)

kelemen commented 6 years ago

I have upgraded the Tooling API both on master and on the nb9 branch. So, anyone interested can try build the plugin from the sources themselves.

thuryn commented 6 years ago

it works fine, thank you