Gradle-based Grails 2.5.5 Project Import does not recognize project as a Grails project
I have re-factored my grails 2.5.5 project to use grails-gradle-plugin:2.2.0.RC1. Upgrading to grails 3 is not an option as the server infrastructure is currently stuck on a platform that only supports version 2.5 of the servlet api.
If I import the project as a gradle project, I can run my gradle tasks without any issues, however all of the grails functionality in the IDE seems to be broken and code inspections complain about missing classes (from grails).
If I import the project "from existing sources" then it is recognized as a grails project, and all my grails-related classes can be found, however because my BuildConfig is empty (having moved all of them into build.gradle), none of the project dependencies are available. So I can't run the app or tests, and code inspections complain about missing classes (from my dependencies)
What is the correct way to import a gradle-based Grails Project into Intellij such that it is recognized as both a grails and a gradle project,
Thanks,
Dave
Please sign in to leave a comment.
I've asked the responsible developer to comment, but it may be unsupported configuration.
Related issue: https://youtrack.jetbrains.com/issue/IDEA-160016.
I'm seeing this issue with one of our own projects as well. Again, this was a project that worked in IntelliJ 2014, but in IntelliJ 2016 (and 2017) it seems that I can either get IntelliJ to pick up the project as a Grails project (with failed builds due to dependancies) OR I can import the Gradle configuration and lose all of IntelliJ's Grails intelligence.
I can also replicate this issue following the IntelliJ documentation at https://www.jetbrains.com/help/idea/2016.3/creating-gradle-project-with-grails-integration.html in IntelliJ 2016.3.5. After following the instructions, the Grails View does not become available as the documentation indicates it should.
However, I can re-import the project created above "From Existing Sources" and it is recognized as a Grails application, and I'm provided with the default Grails run-app run configuration. But I've lost the Gradle tool window, and the message "Unlinked Gradle Project" appears in the event log.
In the "Unlinked Gradle Project" message, I click the provided link to import the gradle project. As soon as I do this, IntelliJ no longer seems to recognize the application as a Grails app: for example, the Application setting of the Grails run-app run configuration is now set to "[None]".
I tried adding grails-core to the dependencies with the hope that IntelliJ would detect the grails dependencies and infer that it was a grails project. No dice. Intellij still treats it as a non-grails project.
Serge is there any chance you could find out what criteria IntelliJ uses to determine if a project is a grails project? Maybe ping the developer again for a response?
Thanks,
Dave
We dropped https://github.com/grails/grails-gradle-plugin support in 2016.2.
Workarounds:
1. Use 2016.1
2. Use gradle idea plugin. Basically the idea is to get dependencies from Gradle without linking the project to Gradle.
- add `apply plugin: 'idea'` to build.gradle
- execute `gradle idea` in terminal. Gradle idea plugin produces IntelliJ project structure good enough to work with the project. However it may need couple of tweaks.
- open project as regular one without importing as Gradle. At this point you get Grails insight but still cannot run Grails commands from within IntelliJ.
- (optional) Configure Grails SDK. The best way is to download SDK via http://sdkman.io.
Please be aware that Grails 2.x knows nothing about Gradle, so select appropriate version of the SDK.
This step messes up with module dependencies, because IntelliJ implementation relies on dependencies configured within BuildConfig.groovy, you may want to remove all dependencies from BuildConfig.groovy and synchronize again. This will allow to run Grails commands from within IntelliJ, i.e. create-controller, create-domain, etc., as well as run/debug Grails apps.
3. Migrate to Grails 3.x which is built on top of Gradle.
Thanks for the helpful response. My preference would be to move to grails 3, however the client does not support anything higher than java 1.6 and servlet 2.5. I will look into using the idea plugin to generate the project structure.
Dave