简体   繁体   中英

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

在此处输入图片说明

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!

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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