Search code examples
javagradleintellij-ideaintellij-plugin

Gradle fails trying to build class using PsiMethod in IntelliJ Plugin project


I have a Intellij plugin project that I can successfully build without using the PsiMethod class. I've generated this project using this intellij plugin guide

As soon as I add in code using PsiMethod class (from the Intellij SDK code_samples directory)

The intellisense cannot find any GOTO information for the class.

I can then switch my project settings module from JAVA_1.8.0 to

enter image description here

by adding it into the platform settings SDKs:

enter image description here

This now adds intellisense, and gives me the ability to navigate to the PsiMethod class by CMD+click.

However, If I try and run my "plugin" gradle configratuion. it halts with an error running :runIde.

Running compileJava command from bash I get:

$ ./gradlew compileJava


> Task :compileJava FAILED
/Users/cody/IdeaProjects/plugintest/src/main/java/com/plugintest/TestClass.java:104: error: cannot find symbol
            PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
            ^
  symbol:   class PsiMethod
  location: class ParticleContainerManager
/Users/cody/IdeaProjects/plugintest/src/main/java/com/plugintest/TestClass.java:104: error: cannot find symbol
            PsiMethod containingMethod = PsiTreeUtil.getParentOfType(element, PsiMethod.class);
                                                                              ^
  symbol:   class PsiMethod
  location: class ParticleContainerManager
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
2 errors

The gradle source sets in intellij are as follows: enter image description here

And when I CMD+Click the PsiMethod class, it shows the following JAR source: jar source

This source is in the following parent folder:enter image description here

How can I add this source into my gradle configuration? shouldn't it be autodetecting what my projects intellisense is tapping into?

Do I need to change something in the gradle.* files inside the project directory?

EDIT: Using Yann's Answer:

I've added the following line to my build.gradle file:

intellij {
    version '2019.2'
    plugins 'java'
}

and it works!


Solution

  • Please make sure to add Java plugin as separate dependency. This is now necessary starting with 2019.2: https://blog.jetbrains.com/platform/2019/06/java-functionality-extracted-as-a-plugin/