简体   繁体   English

在IntelliJ IDEA中设置Grails项目

[英]setup Grails project in IntelliJ IDEA

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. 在grails-app / conf / BuildConfig中,我添加了必要的配置以确保从plugins目录加载plugins ,这样当我运行应用程序时,它会获取最新的更改。

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. 我试图将它设置为IntelliJ中的单个项目,它有3个模块,一个用于主应用程序,另一个用于两个插件。 I tried the following: 我尝试了以下方法:

  • Generate the IntelliJ project files 生成IntelliJ项目文件

    cd my-app/main-app

    grails integrate-with --intellij

  • Open the generated .ipr file from inside Intellij (File | Open Project...). 从Intellij(File | Open Project ...)中打开生成的.ipr文件。 This adds the main application and plugins as Grails modules 这将主应用程序和插件添加为Grails模块

However every time I open a class from a plugin, IntelliJ reports that the class has two occurrences. 但是每次我从插件中打开一个类时,IntelliJ都会报告该类有两次出现。 It seems each plugin class is being detected 似乎正在检测每个插件类

  1. once in the IntelliJ module for the plugin itself 一次在IntelliJ模块中为插件本身
  2. once in the module that IntelliJ automatically creates which contains all the plugins. 一次在IntelliJ自动创建的模块中,其中包含所有插件。 In my case, this module is named main-app-grailsPlugins 在我的例子中,这个模块名为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. 在项目结构视图中,我尝试从main-app-grailsPlugins删除plugin1plugins2的内容根,但它们会自动重新添加回来。

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. 有没有办法防止这种情况,或者为使用就地插件的Grails应用程序正确设置IntelliJ项目的其他方法。 I'm using Grails 1.3.7 and IntelliJ 10.5.4 我正在使用Grails 1.3.7和IntelliJ 10.5.4

With IntelliJ IDEA 12 Ultimate this is very easy: 使用IntelliJ IDEA 12 Ultimate,这非常简单:

"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. inplace插件将自动添加为模块。 Result: http://d.pr/i/YHkk 结果: http//d.pr/i/YHkk

The following has worked beautifully for me in a similar situation: 在类似情况下,以下内容对我来说非常有效:

  1. Make sure that your local plugins are referenced correctly: 确保正确引用了本地插件:

    grails.plugin.location.MyPlugin= "../plugins/MyPlugin"

  2. Start out by creating an empty project - that is, no modules! 首先创建一个空项目 - 也就是说,没有模块!
  3. Do not import or in any other way "autogenerate" ipr files 不要导入或以任何其他方式“自动生成”ipr文件
  4. Important! 重要! Start out with the lower plugins in your "dependency graph" 从“依赖关系图”中的较低插件开始
  5. Click file->New Module 单击文件 - >新模块
  6. Choose grails module 选择grails模块
  7. Point "content root" to the root of your plugin (Module name should be filled in automatically) 将“内容根”指向插件的根目录(模块名称应自动填写)
  8. Repeat 5-7 until no more plugins 重复5-7直到没有更多的插件
  9. Finish by creating a module for your main app in similar manner as 5-7 完成后,以与5-7类似的方式为主应用程序创建模块

This does it for me with many more plugins than two! 这对我来说有更多的插件而不是两个!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM