【问题标题】:After installing the spring-security-core grails plugin, how do you get IDEA to know about the jar files?安装完spring-security-core grails插件后,如何让IDEA知道jar文件?
【发布时间】:2011-02-24 12:27:06
【问题描述】:

我在一个 grails 项目中安装了 spring-security-core,但由于某种原因,IDEA 没有自动提取 jar 文件。我可以很好地使用 grails 命令行部署应用程序并运行测试......但 IDEA 仍然会使用波浪线。有没有办法让 IDEA 在我安装插件后自动拾取 jar?

【问题讨论】:

    标签: grails plugins jar intellij-idea installation


    【解决方案1】:
    1. 打开项目结构窗口
    2. 在项目设置中选择模块
    3. 然后选择插件模块。它应该被命名为“myproject-grailsPlugin”
    4. 然后选择选项卡依赖项
    5. 在依赖模块中,选择 Grails User Library(如果不存在,使用 Add -> Global Library 创建)
    6. 编辑此库并在“配置模块库”对话框中,选择“附加 JAR 目录”
    7. 选择spring-security-code插件的lib目录。 O windows 它应该位于:C:\Users\myuser.grails\1.3.1\projects\myproject\plugins\spring-security-core-0.3.1\lib

    就是这样!

    【讨论】:

    • spring-security-core-0.3.1 没有 lib/ 目录。
    【解决方案2】:

    我不是 100% 这个问题的真正根源是什么。据我所知,IntelliJ 会解析插件内部的 BuildConfig.groovy 来配置依赖项。看来,它确实拾取自动生成的dependencies.groovy。打包的 spring-security-core 插件只包含一个 dependencies.groovy,没有 BuildConfig.groovy。

    我已将以下 sn-p 添加到我的应用的 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'
    }
    

    有了这个,IntelliJ “知道” Spring Security jars。

    【讨论】:

    • 这个解决方案很棒。它同时影响项目中的每个人。你摇滚!
    • 我没有尝试过,但 IntelliJ 可能已经在他们最新的 EAP 中修复了这个问题。
    • 对此进行跟进:在 IntelliJ 9.0.3 中,不再需要上述 hack。
    【解决方案3】:

    为什么不直接右键单击您的项目根目录并单击“同步 grails 依赖项”...

    【讨论】:

      【解决方案4】:

      我的问题(9.0.2)是 grailsPlugins 的类路径上没有 grails 库。所以编译依赖不起作用,你的修复 fabien 有点冗长:-)

      IDEA 通常具有出色的自动错误修复功能(alt + enter),并且在这种情况下可以正常工作。它会要求您“将 grails 用户库添加到类路径”。像魅力一样工作,但应该没有必要

      【讨论】:

        【解决方案5】:

        当您将插件目录更改为 BuildConfig.groovy 中默认目录以外的目录时,似乎 intellij 9.0.3 无法正确地从插件中获取依赖项

        grails.project.plugins.dir = "./plugins"  //breaks plug-ins in intellij
        

        更改插件目录后开始出现找不到类错误。我添加了模块中的依赖项(即 spring-security-core 和 springcache),现在 intellij 将 jar 依赖项添加到“Grails 用户库”中,我可以编译我的应用程序。使用命令行从来没有任何问题。

        这是我为 springcache 添加到 BuildConfig 中的内容。

        dependencies {   
        //for spring-security-core
        

        // 用于springcache 编译(“net.sf.ehcache:ehcache-web:2.0.0”){ excludes "ehcache-core" // ehcache-core 由 Grails 提供 }

        }

        【讨论】:

          猜你喜欢
          • 2011-07-07
          • 2016-03-23
          • 2012-09-29
          • 2012-10-17
          • 2015-02-05
          • 2012-11-04
          • 2015-06-18
          • 1970-01-01
          • 2011-06-29
          相关资源
          最近更新 更多