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

半腔热情 提交于 2021-01-29 03:22:08

问题


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

by adding it into the platform settings SDKs:

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:

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

This source is in the following parent folder:

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!


回答1:


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/



来源:https://stackoverflow.com/questions/57538497/gradle-fails-trying-to-build-class-using-psimethod-in-intellij-plugin-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!