views:

596

answers:

4

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?

A: 
  1. Open Project Structure Window
  2. in Project Settings choose Modules
  3. then choose the plugin module. It should be named "myproject-grailsPlugin"
  4. then select the tab dependencies
  5. Inside the dependent modules, select Grails User Library (if it does not exist, create it with Add -> Global Library)
  6. EDIT this library and inside the Configure Module Library dialog, choose "Attach JAR directories"
  7. 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 !

fabien7474
spring-security-core-0.3.1 don't have lib/ dir.
Edvinas Bartkus
+1  A: 

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.

Stefan
This solution is great. It affects everyone on the project at the same time. You rock!
egervari
I have not tried, but IntelliJ might have fixed this in their latest EAP.
Stefan
Just a follow up on this: in IntelliJ 9.0.3 the above hack is no longer necessary.
Stefan
A: 

why not just right click on your project root directory and click 'synchronize grails dependencies'...

hvgotcodes
A: 

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

Rune