Gradle无法尝试在IntelliJ插件项目中使用PsiMethod构建类

时间:2019-08-17 17:29:47

标签: java gradle intellij-idea intellij-plugin

我有一个Intellij插件项目,无需使用PsiMethod类就可以成功构建该项目。我已经使用此intellij plugin guide

生成了这个项目

使用PsiMethod类添加代码后, (来自Intellij SDK code_samples directory

智能感知无法找到该类的任何GOTO信息。

然后我可以将项目设置模块从JAVA_1.8.0切换到

enter image description here

通过将其添加到平台设置SDK中:

enter image description here

这现在增加了智能感知能力,使我能够通过CMD + click导航到PsiMethod类。

但是,如果我尝试运行“插件” gradle配置。它会因运行:runIde的错误而停止。

从bash运行compileJava命令,我得到:

$ ./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

intellij中的gradle源集如下: enter image description here

当我CMD +单击PsiMethod类时,它显示以下JAR源: jar source

此来源位于以下父文件夹中:enter image description here

如何将该源添加到我的gradle配置中?是不是应该自动检测我的项目intellisense正在使用什么?

我是否需要在项目目录中的gradle。*文件中进行某些更改?

编辑: 使用Yann的答案:

我已将以下行添加到我的build.gradle文件中:

intellij {
    version '2019.2'
    plugins 'java'
}

它有效!

1 个答案:

答案 0 :(得分:2)

请确保添加Java插件作为单独的依赖项。从2019.2开始,这是必须的:https://blog.jetbrains.com/platform/2019/06/java-functionality-extracted-as-a-plugin/