setup Grails project in IntelliJ IDEA - grails

I have the following directory structure
--my-app
|
|--main-app
|
|--plugins
|
|--plugin1
|
|--plugin2
In grails-app/conf/BuildConfig I've added the necessary configuration to ensure that the plugins are loaded from the plugins directory, so that when I run the application, it picks up the most recent changes.
I'm trying to set this up as a single project in IntelliJ which has 3 modules, one for the main application and one for each of the two plugins. I tried the following:
Generate the IntelliJ project files
cd my-app/main-app
grails integrate-with --intellij
Open the generated .ipr file from inside Intellij (File | Open Project...). This adds the main application and plugins as Grails modules
However every time I open a class from a plugin, IntelliJ reports that the class has two occurrences. It seems each plugin class is being detected
once in the IntelliJ module for the plugin itself
once in the module that IntelliJ automatically creates which contains all the plugins. In my case, this module is named main-app-grailsPlugins
In the project structure view I tried removing the content roots for plugin1 and plugins2 from main-app-grailsPlugins, but they get automatically added back again.
Is there a way to prevent this, or some other way of correctly setting up an IntelliJ project for a Grails app with in-place plugins. I'm using Grails 1.3.7 and IntelliJ 10.5.4

With IntelliJ IDEA 12 Ultimate this is very easy:
"File"
--> "Import Project..."
--> select your grails application, "OK"
--> Select "Create project from existing sources", "Next"
--> "Next"
--> "Next"
--> Select JDK, "Next"
--> Select grails version, "Next"
--> "Finish"
The inplace plugins will automatically be added as modules.
Result: http://d.pr/i/YHkk

The following has worked beautifully for me in a similar situation:
Make sure that your local plugins are referenced correctly:
grails.plugin.location.MyPlugin= "../plugins/MyPlugin"
Start out by creating an empty project - that is, no modules!
Do not import or in any other way "autogenerate" ipr files
Important! Start out with the lower plugins in your "dependency graph"
Click file->New Module
Choose grails module
Point "content root" to the root of your plugin (Module name should be filled in automatically)
Repeat 5-7 until no more plugins
Finish by creating a module for your main app in similar manner as 5-7
This does it for me with many more plugins than two!

Related

Intellij IDEA 13.1 isn't creating new Grails Projects

My Intellij IDEA 13.1.4 Ultimate isn't creating new Grails projects using "File" > "New Project".
I mark my project as Groovy Project then I select Grails. I setup a Groovy Library pointing to my Grails 2.4.3 home (I've tried with 2.3.11 and 2.2.5). I click Next and put a name for my project.
Then, when I finish this process, the Intellij Window opens but the Grails "create-app" script doesn't runs and the project isn't properly configured. The folders like "grails-app" and "web-app" aren't created. No log error or warn was generated.
Importing an project works well.
Instead of choosing grails in the menu choose groovy and then select the grails library like this:
that will somehow trigger the create-app script
this is a bug in IDEA, see IDEA-127693

Grails/GGTS 2.4.2 not putting plugins on classpath?

I am trying to update an older 1.3 Grails project to the latest Grails/Groovy/etc. So I downloaded Grails 2.4.2, Groovy 2.3, and Java 1.7.0_65. Then I imported the project via Import->Grails. I found out that plugins are now configured via the BuildConfig.groovy file, so I edited that with the plugins section and ran Grails Tools -> Update Dependencies. None of my plugins appear on the classpath? However, if I startup the plugin manager (which I'm not fully clear on why it is in the product as it states it won't do much after version 2.3...), it does list:
Plug-ins you currently have installed are listed below:
-------------------------------------------------------------
mail 1.0.6 -- Provides Mail support to a
running Grails application
routing 1.2.0 -- Routing capabilities using
Apache Camel
routing-jms 1.2.0 -- JMS integration for the
grails-routing plugin
shiro 1.2.1 -- Apache Shiro Integration for Grails
So SOME part of Grails seems to know about the plugins. Also, if I delete the plugins from my $HOME/.grails/projects/myProject/plugins directory and re-run the Grails Tools -> refresh dependencies, I get both text on the console saying they are being installed and they come back to that directory.
The ONLY thing that seems abnormal, is that during the second set of files compiled (my project files) there ARE compile errors. I expected these (for instances of grailsApplication / etc). To fix them, I wanted to use GGTS - however, there are SO many compile errors in there from the plugins not being on the classpath it is not very feasible.
If anyone has ideas or suggestions for me to try that would be greatly appreciated!
I think it's a problem with GGTS not knowing what your grails work directory is.
You can check you .project file to see if the .link_to_grails_plugins resource is defined correctly.
GGTS may have created the .project like this
<linkedResources>
<link>
<name>.link_to_grails_plugins</name>
<type>2</type>
<locationURI>GRAILS_ROOT/projects/myProject/plugins</locationURI>
</link>
</linkedResources>
GRAILS_ROOT is a variable defined in your GGTS Preferences under General -> Workspace -> Linked Resources
You might have to add the variable if it's not there.
Set the value to the absolute path for $HOME/.grails and then try to refresh your dependencies.

Tomcat Maven plugin and multi-module Maven projects

We have an application that until recently was a single Maven WAR project. We were using the Tomcat Maven plugin to run the application on local developer workstations using:
mvn tomcat:run
We were able to change JSP files while the embedded Tomcat instance was running and the changes would appear in web browsers just fine. I understand (from the plugin documentation) that when using the tomcat:run goal, the WAR is loaded as a dynamic web application and hence changes made to JSP files at source are picked up by Tomcat at runtime without restart.
The application has reached a fairly large size and we needed to reuse a large number of classes in a few different places besides the web project, so we refactored the code base into a multi-module Maven project. The structure is now:
parent Maven POM
|
---- artifact1.jar
|
---- artifact2.jar -> depends on artifact1.jar
|
---- artifact3.jar -> depends on artifact1.jar
|
---- artifact4.jar -> depends on artifact2.jar and artifact3.jar
|
---- artifact5.war -> depends on artifact1.jar, artifact2.jar, artifact3.jar and artifact4.jar
After the refactoring we were unable to use tomcat:run from the project's root directory to run the WAR project as the plugin was unable to detect the JAR artifacts. So, we switched to using the tomcat:run-war-only plugin. The WAR module now launches fine.
However, from the documentation, it seems that the run-war-only goal treats WAR files as packaged web applications. Therefore, any changes we make to JSP files now are not picked up by the embedded Tomcat server while running. For every change to JSP files we have to restart the server.
Is there a way for us in this multi-module Maven set up to run WAR projects as dynamic web applications so that at least changes to JSP files are picked up by Tomcat without restarting?
Just do an mvn install first and then
mvn -pl artifact5 tomcat:run
First use new version of the tomcat plugin now located at Apache see http://tomcat.apache.org/maven-plugin-2.0/.
Then if you use maven3, you simply use tomcat6/tomcat7:run from the top. All classes from modules will be added to your webapp classloader (will save some ios as you don't need to install all jars first !) see http://tomcat.apache.org/maven-plugin-2.0/run-mojo-features.html
HTH!

Mismatch between grails installed plugins list and intellij 11 list

I have a grails 2.0 app which I have installed the resources plugin into, when I look at the list of installed plugins in intellij it doesnt have it ticked, however if I do a 'grails list-plugins' it shows as being installed. Is there any way to refresh or correct the list in intellij? Other plugins have installed fine, and I have tried reloading the list in intellij.
IDEA looks into %USER_HOME%/.grails/2.0.0/projects/%PROJECT_NAME%/plugins to determinate which plugins are installed. Make sure that that folder contains unpacked 'resource' plugin.
If that folder contains unpacked plugin right click on grails project then select Grails -> "Synchronize Grails Settings" in the context menu.
Going to File -> Invalidate Caches fixes this problem, the lists now match (note: this does delete your local history also)

After installing the spring-security-core grails plugin, how do you get IDEA to know about the jar files?

I have installed spring-security-core in a grails project, but for some reason, IDEA didn't automatically pick up the jar files. I can deploy the app and run tests using the grails command line just fine... but IDEA still puts squiggly lines. Is there a way I can get IDEA to automatically pick up jars after I install plugins?
I'm not 100% what the real source of this problem is. To my knowledge, IntelliJ parses the BuildConfig.groovy inside plugins to configure dependencies. It seems, that it does not pickup the autogenerated dependencies.groovy. The packaged spring-security-core plugin just contains a dependencies.groovy and no BuildConfig.groovy.
I've added the following snippet to my app's BuildConfig.groovy
dependencies {
compile('org.springframework.security:org.springframework.security.core:3.0.2.RELEASE') {
excludes 'com.springsource.org.aopalliance',
'com.springsource.org.apache.commons.logging',
'org.springframework.beans',
'org.springframework.context',
'org.springframework.core'
}
compile('org.springframework.security:org.springframework.security.web:3.0.2.RELEASE') {
excludes 'com.springsource.javax.servlet',
'com.springsource.org.aopalliance',
'com.springsource.org.apache.commons.logging',
'org.springframework.aop',
'org.springframework.beans',
'org.springframework.context',
'org.springframework.core',
'org.springframework.web'
}
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
// runtime 'mysql:mysql-connector-java:5.1.5'
}
With this, IntelliJ "knows" about the Spring Security jars.
The problem in my case (9.0.2) was that the grailsPlugins did not have grails library on it's classpath. So the compile dependencies would not work, and your fix fabien is a bit to verbose :-)
IDEA normally has a great auto error fix (alt + enter) and it works in this case to. It will ask you to "Add grails user library to classpath". Works like a charm but should offcourse not be necessary
Open Project Structure Window
in Project Settings choose Modules
then choose the plugin module. It should be named "myproject-grailsPlugin"
then select the tab dependencies
Inside the dependent modules, select Grails User Library (if it does not exist, create it with Add -> Global Library)
EDIT this library and inside the Configure Module Library dialog, choose "Attach JAR directories"
Select the lib directory of the spring-security-code plugin. O windows it should be located ate : C:\Users\myuser.grails\1.3.1\projects\myproject\plugins\spring-security-core-0.3.1\lib
That's it !
why not just right click on your project root directory and click 'synchronize grails dependencies'...
It seems like intellij 9.0.3 does not correctly pick up dependencies from plugins when you change the plugin directory to something other other than default one in BuildConfig.groovy
grails.project.plugins.dir = "./plugins" //breaks plug-ins in intellij
Class not found errors started appearing after changing the plugin directory. I added the dependencies from the modules (namely spring-security-core and springcache) and now intellij adds the jar dependencies to 'Grails user library' and I can compile my app. Using the command line never had any issue.
Here's what I added to BuildConfig for springcache.
dependencies {
//for spring-security-core
// for springcache
compile("net.sf.ehcache:ehcache-web:2.0.0") {
excludes "ehcache-core" // ehcache-core is provided by Grails
}
}

Resources