Are grails plugins compiled at publish time - grails

I see that grails plugins compile files of plugins too. So I am guessing grails plugins are not compiled into bytecode. Is there a way to make grails plugins compile into bytecode so they are not compiled over and over in all projects that have them as dependency?
Note: I'm using grails 2.4.3 but this question may apply to other versions as well.

So I am guessing grails plugins are not compiled into bytecode.
Grails plugins are compiled to bytecode. There is no other way to execute Groovy or Java code.
Is there a way to make grails plugins compile into bytecode so they
are not compiled over and over in all projects that have them as
dependency?
The code has to be compiled into bytecode before it can be executed. In the old plugin system (Grails 1 and 2), that happened at application compile time. With Grails 3 and Grails 4, plugins are compiled when they are distributed so when an app consumes them, the code has already been compiled to bytecode so the code is still being compiled to bytecode, but that is happening once when the plugin is published as opposed to happening when the app that uses the plugin is compiled.

Related

IntelliJ 15 and Grails 3: unable to find grails packages

I'm converting a grails 2 plugin to grails 3, using IntelliJ 15.0 Community Edition. For Java files only, IntelliJ gives me many errors about missing packages and symbols from Grails. For example:
Error:(20, 19) java: package grails.core does not exist
and
Error:(23, 41) java: cannot find symbol
symbol: class AbstractGrailsClass
I have tried adding dependencies in Project Structure so as to point to the grails sources, but that didn't seem to have any effect. I admit I am a novice when it comes to IntelliJ, so this may be a simple config setting.
In IntelliJ's preferences set up a Grails SDK Home. Open Preferences then type Grails to bring up the page. Then set it to point to your Grails installation e.g.
/Users/whoever/.sdkman/candidates/grails/current
One thing to consider is that Grails 3 requires moving .java files from src/main/java to src/main/groovy
This may be related to why you are experiencing problems.

Grails GGTS "Task 'assemble' not found in root project" error when running "grails war" in Command Prompt

I have been learning Groovy/Grails Tool Suite (GGTS) 3.6.4, with Grails 2.4.4 using some video tutorials. When I attempt to package the project into an application using the grails war command on the Windows command prompt, I get the following error:
"Error Gradle build terminated with error: Task 'assemble' not found in root project ..."
Any references to this error that I have found online have only involved Android Studio (for instance), so I am at a loss here as to how to fix it for GGTS.
I have Android Studio 1.0.1 installed, and in case it was affecting the Grails packaging, I tried the solution of removing the <component name="FacetManager"> from the general Android Studio "MyApplication.iml" file, but that had no effect. I couldn't find any analogous file for the GGTS.
In case the issue lies elsewhere in my overall installation, I have Java JRE 7_79 (64-bit) installed, as well as the the JDK 1.7.0_79 (64-bit)
OK. I found out what the cause of the error was, and how to avoid it in the future.
The Problem
Grails 3.0.1 requires the following files for grails war to work:
build.gradle
gradle.properties
gradlew
gradlew.bat
\gradle (directory)
Grails 2.4.4 does not require any of the above files for making a WAR file.
GGTS 3.6.4 does not work with Grails 3.0.1, but it comes with and works fine with Grails 2.4.4.
The Solution
Copying the stated Gradle files & directory to a GGTS project folder fixed the problem. However, I wasn't satisfied with needing to do this manually or with a custom batch file for every project.
Looking deeper, it turns out that when working out compatibility issues between the Java 32-bit JRE existing on my system and the Java 64-bit JRE & SDK, Grails, and GGTS versions (there was a lot of fiddling to get things working), at one point I had set up my global variable to Grails to be directed at 3.0.1, and I failed to update it to Grails 2.4.4. Making this change has fixed the issue.
Explaining the Cause
When following this video series on installing a compatible set of Java, Grails, and GGTS, the instructor manually downloaded the latest version of Grails from the Grails site and then downloaded GGTS separately from its own site. Both of these were older versions than what I was working with.
In my case it turns out that, after setting up the Java SDK & Grails, the latest version of GGTS (3.6.4) did not work properly with the latest version of Grails (3.0.1). Fortunately the GGTS bundle came with an older version of Grails (2.4.4), and by referencing that, GGTS would work correctly. However, although I changed the IDE reference to Grails, I forgot to reset my environment variable ...
So GGTS was setting up the project for using Grails 2.4.4. However, when calling grails war, the command was using Grails 3.0.1! Apparently these two versions of Grails use different files for creating a WAR file, so GGTS was not setting up the project directories with the correct local files, and the packaging was failing.
Avoiding Future Occurrences
So, when using GGTS 3.6.4, make sure that all references to Grails point to Grails 2.4.4.
In general, if any GGTS bundle contains a version of Grails, you should have everything set up to use that version, even if it is old.

Grails, GGTS Setup

I need to setup a Windows working environment for Grails. I'd like to use GGTS as an IDE but got several errors compiling a sample project. Currently I'm using jdk1.8.0_40 and Grails 2.5.0. which results in this error (but in the end the project is working):
Groovy:Unexpected problem with AST transform: The Spock compiler
plugin cannot execute because Spock 1.0.0-groovy-2.4 is not compatible
with Groovy 2.3.10. For more information, see http://versioninfo.spockframework.org
On top of that there are two Java Exception Breakpoints which are listed as "unknown". Only info regarding version support I could find is:
Java SDK 1.5+ for Grails 1.2 or greater
GGTS itself seems not to run with the latest grails (3.0.1) since I simply cannot add it (directory appears not to be a grails installation).
Should I use Java 7 instead?
This issue is not related to JDK 1.8 or 1.7, but its is related to the GGTS IDE 3.6.4 Groovy Compiler version. As the error clarifies that Spock 1.0.0 version needs Groovy 2.4 compiler.
GGTS 3.6.4.RELEASE-e4.4.2 IDE comes with Groovy 2.3.10 compiler by Default.
Install Groovy Compiler 2.4 Feature and "switch to 2.4" will resolve this issue.
Refer: http://docs.codehaus.org/display/GROOVY/Compiler+Switching+within+Groovy-Eclipse
If you cannot switch compilers from the IDE Groovy Compiler preference page, follow the instructions to perform the switch from outside of Eclipse:
(Grails 2.5.0 uses Spock 1.0.0 (and internally Groovy 2.4.3 and this is why your project is compiling & working fine as the Grails runtime environment is taking over)
As an additional experience report to the answer above, thus providing another solution variant: I had to use the http://dist.springsource.org/snapshot/GRECLIPSE/e4.4 update site (as opposed to the release version mentioned in the link above) to make the 2.4 compiler feature available in the update manager.
After installation, the compiler errors are gone.
I noticed that project-specific groovy compiler is set in the Groovy Compiler preference page in new grails projects. By selecting "I don't care" for "Groovy compiler" it will default to the workspace groovy compiler which is usually correct (for me it's version 2.4). This worked for me but experience may vary.

Netbeans groovy 1.8 support

I am using NetBeans 7.1, which comes with Groovy 1.6 support. I have to do a Grails project, but with Groovy 1.8 support. So I downloaded Groovy 1.8 installer, installed it and added the Library in Netbeans -> Tools -> Libraries (and removed Groovy 1.6 library).
Now whenever I use some stuff added in Groovy 1.8 within my Grils project, it still underlines it and throws "cannot resolve" error... I was googling it for last 2 hours and everything I find seems I have already done... it starts to give me a headache... Any suggestions on how to solve it?
NetBeans support from Groovy has -- until recently -- stagnated.
The Groovy support (as you say) is for Groovy 1.6.X, and the Grails support is similarly old.
There has very recently been some activity in trying to improve this, but at the current time you are probably better using Eclipse, STS (both free) or IDEA (paid) if you want proper IDE support for up to date Grails development.

SpringSource: Grails plugins

More often when I install a plugin, doesn't recognize it.
For example using Joda Time, I have a variable LocalDateTime date (i'm importing joda library) and eclipse says unable to resolve class LocalDateTime, though the application works.
Or I have installed the grails icepush plugin but after the installation taglib files were missing.
It's a SpringSource problem?
You should upgrade to SpringSource Tool Suite (STS) which is Eclipse bundled with a suite of plugins. It has great support for Groovy and Grails. 2.5.0 was recently released and it has a plugin wizard for installing, updating, and uninstalling plugins, although it supports plugins installed from the commandline too. I find I sometimes need to manually refresh it but that's simple - just right-click on the project and select Grails Tools | Refresh Dependencies.
After installing you'll need to add support for Groovy and Grails - that's available from the Dashboard.
Download from http://www.springsource.com/developer/sts
You are not doing anything wrong, chances are the eclipse toolset is still behind the competition. As mentioned by #Burt, you can get the STS from SpringSource directly or you can get IntelliJ IDEA which also has a very good clean interface to Grails applications. The latest 9.0.3 works very well with large, complex Grails applications, and seems to have a very advanced intellisense (autocomplete) capabilities.

Resources