Error running forked groovyc caused in Netbeans - groovy

I installed Netbeans 11.3 under Ubuntu 18.04 and created in the following a new Groovy project.
Choose File > New Project (Ctrl-Shift-N;\u2318-Shift-N on Mac) from the main menu to open the New Project wizard.
Select Java Application in the Java category. Click Next.
Type GroovyJavaDemo as the Project Name and specify the folder where you want to create the application in the Project Location field.
Deselect the Create Main Class checkbox. Click Finish.
Next, I created a Groovy Script file with only this content println "Hello" and it caused the following problems:
ant -f /home/ubuntu/NetBeansProjects/GroovyJavaDemo -Djavac.includes=Hello.groovy -Drun.class=Hello run-single
init:
deps-jar:
Created dir: /home/ubuntu/NetBeansProjects/GroovyJavaDemo/build
Updating property file: /home/ubuntu/NetBeansProjects/GroovyJavaDemo/build/built-jar.properties
Created dir: /home/ubuntu/NetBeansProjects/GroovyJavaDemo/build/classes
Created dir: /home/ubuntu/NetBeansProjects/GroovyJavaDemo/build/empty
Compiling 1 source file to /home/ubuntu/NetBeansProjects/GroovyJavaDemo/build/classes
/home/ubuntu/NetBeansProjects/GroovyJavaDemo/nbproject/build-impl.xml:1120: The following error occurred while executing this line:
/home/ubuntu/NetBeansProjects/GroovyJavaDemo/nbproject/groovy-build.xml:26: Error running forked groovyc.
BUILD FAILED (total time: 1 second)
What did I miss?
Thank you in advance,

I don't think you missed anything, since I can reproduce your problem with JDK 11 on NetBeans 11.3.
However, there is a (somewhat unsatisfactory) workaround that worked for me:
Install JDK 8 (if necessary).
Edit the NetBeans file etc/netbeans.conf and set the JDK that NetBeans uses to JDK 8. In my case I added the line netbeans_jdkhome="C:\Java\jdk1.8.0_221" to netbeans.conf.
Restart NetBeans then rebuild your project. It should compile now:
Notes:
You could bug report this issue to the NetBeans team if you wish.
I also tried using JDK 14 as the default Java platform for NetBeans and got a different error: NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7. See the Gradle bug JDK 14 support #10248 for more information on that.
Setting JDK 8 as the default platform for NetBeans doesn't prevent you from adding other Java platforms (Tools > Java Platforms > Add Platform...) such as JDK 11 and JDK 14 for your individual projects.

Edit the groovy-build.xml and replace <groovyc javahome="${platform.home}" with <groovyc javahome="${jdk.home}" it works for me on JDK 1.8

Please find here the solution for Open-JDK-13

Related

How can I use gradle installed in WSL alongside Android Studio installed on Windows

I've recently had to start developing a Micronaut project in Android Studio instead of IntelliJ IDEA Ultimate. I'd assumed that because they share the same base this would be fine but when I load up my project I get this (the project is held in the wsl filesystem and all development has been using WSL with IDEA):
14:07 Project [name] is using the following JDK location when running Gradle:
//wsl$/Ubuntu-22.04/usr/lib/jvm/java-11-openjdk-amd64
Using different JDK locations on different processes might cause Gradle to
spawn multiple daemons, for example, by executing Gradle tasks from a terminal
while using Android Studio.
More info...
Select a JDK
Do not show this warning again
It's unclear why this is happening, when I click 'Select a JDK', what is selected is the JDK installed on WSL that IntelliJ is using, likewise it is pointed at the same directory where my gradle properties is kept.
I'm not sure where to go with this, my guess would be maybe Android Studio is trying to run a gradle or java instance that's not the WSL one (I think it installs it's own alongside) and that's the issue but the settings would imply otherwise. Does anyone know what might be happening?
Thanks!

Save Gradle JDK in AndroidStudio BumbleBee between runs

In AndroidStudio BumbleBee, there does not appear to be a way to configure the Gradle JDK that persists between full builds of the target app. Our app requires JDK 8 and Gradle requires JDK 11...
A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.application'.
> Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
- changing the IDE settings.
- changing the JAVA_HOME environment variable.
- changing `org.gradle.java.home` in `gradle.properties`.
We develop our Cordova webapp (JS/CSS) on Mac for desktop first and then port to mobile. We do full builds, not incrementals.
Changing org.gradle.java.home does not work and might be too late as the JDK is already launched to run Gradle and parse org.gradle.java.home.
Changing JAVA_HOME sets the JDK for both our app and Gradle... and all other projects that use Java.
Chaning the IDE settings can be done manually... each full Cordova 11 build and launch of AndroidStudio. Here is how we have to set the Gradle JDK in AndroidStudio preferences... every time we launch Android Studio. Looking for a way to set the Gradle JDK in the IDE that will be honored between runs...
The dropdown includes the embedded JDK 11 that comes with AndroidStudio. This needs to be selected for the Gradle JDK to successfully build our app. Here is the dropdown...
Tried starting AndroidStudio from the commandline, where env variables can be set just for the launched process...
$ JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home" open "/Applications/Android Studio.app"
If there are no options in BumbleBee, are there plans for such support in later releases of Android Studio.

Android Studio shows an error when trying to use Embedded JDK instead of a custom install

After I updated to Android Studio 2.3, I haven't been able to use the embedded JDK. When I try to build the project, I get errors like this:
Error:The newly created daemon process has a different context than expected.
Java home is different.
Expecting: 'D:\Development\IDE\AndroidStudio\jre' but was: 'C:\Program Files\Java\jre1.8.0_121'.
Please configure the JDK to match the expected one.
Open JDK Settings
But the JAVA_HOME environment variable isn't defined, but I can still use the normal JDK any problems, so I don't believe that's a problem. Where does Android Studio find the JAVA_HOME that prevents me from using the embedded JDK?
I tried uninstalled the system JDK to get it to work, and I updated java, which lead to it pointing to the JRE. I then reinstalled the JDK and when I point to it, it works fine. But I want to use the embedded JDK. Any ideas?
I have tried setting JAVA_HOME in gradle.properties, as linked in comments, but it still shows the error.
The line I added was:
org.gradle.java.home=D:/Development/IDE/AndroidStudio/jre
It should make the embedded JDK work (and change JAVA_HOME in the IDE) but it doesn't. It still leads to the same error mentioned at the top of this post.
In the snippet it says jre, and that was because when I copied it, I had just uninstalled the JDK. Updating the JDK and Java resulted in JAVA_HOME being set to the JDK location, but it isn't defined as an environment variable. I tried deleting the JDK table in Android Studio's config folder, but it did not work.
And what it looks when I set the JDK to be the embedded:
Try to reset your path of your updated JDK. and check it again. May be it will help you. Also clear your android studio temp cache and all.
I fixed this issue by uninstalling all the jdk installation & updates then reinstall only one jdk and assure its env. variables
I do not have a solution but I have the same problem it happens as the android studio opens from java_home/jre thence all JVMs that will fork next will come from this path, while your system varible tells Gradle to get his java.exe from JAVA_HOME
I tried to make gradle read from jre but it falied also i tried to make android studio open from java_home/bin but it falid also
I had the exactly same issue with embedded JDK which was working on Android studio version 2.2.3 and when I updated then every time studio prompts JRE not found then I added system JDK path in project folder and now Whole Android studio hanging and I switched back to Android studio 2.2.3. It seems Android studio 2.3.1 is buggy release.
It seems ,There are some miss match of JDK version.
So Try this:
First Uninstall all Jdk/jre and Android Studio.
Clear temp/prefetch etc.
then Simply Install latest version of Android studio.
Remember: Don't install any other JDK/jre and make sure that your system have proper internet connectivity.All missing file automatically downloaded.
I had try this already and it was work for me .I hope it will also work for you.
I must say the AS has too many trouble in environment settings. There are some concepts we need to know.
AS default java runtime environment itself ,as shown below.
AS default java runtime environment itself.
System has another Java_home as shown below.
System's JDK version
Then problem is coming , what will happen when the system's JDK version doesn't match the AS's JDK version?
i.
java.lang.UnsupportedClassVersionError
ii.
gradle failure:certification ...
iii. There are some other error I couldn't remember now.
Solution:
If your AS update to latest version,you should update your Gradle to latest version,and make sure your system's JDK is match AS's JDK version. At least, your idk version update to more than JDK1.8.0. When you do all of this ,try to restart your AS ,if does works ,try to restart your computer.
Extra:
The proxy software has some influences when Gradle sync, if there are any tips about certificate ,try to close proxy software and try again.

Issue after Android studio update

I just tried to update Android studio from 1.4 to 2.2 preview 2. After updating Android Studio, when I tried to open it, it showed me this error:
Error:(1, 1) A problem occurred evaluating project ':app'.
java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
Can any one help me to resolve this?
I spent quite a lot of time with this one in Android Studio too.
It seems this problem is caused by the difference in java version used for compiling the project.
Finally, inside the "Project Structure" settings window, I enabled the "Use embedded JDK (recommended)" in the SDK location tab.
And happy compiling :)
Your runtime environment is running a different version of Java than your compiler - 52.0 represents Java SE 8
On Linux, type:
sudo update-alternatives --config java
Output will be like:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 auto mode
1 /usr/lib/jvm/java-7-oracle/jre/bin/java 2 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Select 2
Then compile your project:
./gradlew assembleDebug
This fixed it for me:)
On Windows, you can do it via the Java Control Panel very easily - read more about it here!

Resolving: Groovyc: Internal groovyc error: code 1

I'm compiling a project that works OK in Eclipse, and builds fine with ant, but in IntelliJ IDEA gives:
Internal groovyc error: code 1
How can I resolve this? Other error messages include:
1:35:46 PM Unknown Natures Detected
Imported projects contain unknown natures:
org.eclipse.jdt.groovy.core.groovyNature
Some settings may be lost after import.
1:43:55 PM Compilation completed with 1 error and 7 warnings in 20 sec
Groovyc: Cannot compile Groovy files: no Groovy library is defined for module
Groovy itself is installed on Linux. Adding it as a groovy compiler in settings does not affect the behavior:
> groovy --version
Groovy Version: 1.7.4 JVM: 1.6.0_24
Apparently you tried to import an Eclipse project into IDEA, and that isn't good enough. (Groovy) Eclipse comes with its own version of Groovy, whereas in IDEA, you have to add groovy-all-1.7.4.jar (or whatever version you want to use) as a compile dependency.
You have to add JAXB dependencies if you are using Groovy 2.5.3 + Java 11 (also check out Java 11 related change). Groovy comes with extra JAXB Jars so we can add them. Open 'Project Structure' dialog, then select 'Dependencies' tab and add the dependencies
Changing the project SDK from Java 15 to Java 8 seemed to have magically fixed the same problem on my machine.
Steps:
Go to File > Project structure... (may differ on Mac/Linux).
Under Project Settings, select Project.
In Project SDK: dropdown, choose a different version of the JDK installed.
Click Apply & OK at the bottom of the dialog.
** Rerun your program.
This worked for me!!
Read the log before the "Internal groovyc error: code 1", then it should show you a groovy version mismatch. Change your groovy version from the dependency list as per the log.
Ex. compile 'org.codehaus.groovy:groovy-all:2.4.11'
Move the Groovy dependency in the module settings to the top right after JDK.
I could make it work just by reestart intellij and invalidate the caches.
It can be found (for intelliJ 2018.1):
File -> Invalidate Caches/restart -> Invalidate and Restart
I found this solution which worked totally for me. You can use this link for fixing this problem
resolving-groovyc-internal-groovyc-error-code-1
I had to reinstall groovy SDK and it started working.
i was use wrong SDK ,please cheak your SDK version

Resources