Unresolved reference when running gradle:runIde

已回答

Hello friends,

I'm attempting to create an IDE plugin to no avail. The documentation was of no help, and googling IntelliJ plugin development issues brings up results from 2004.

- I've created the git repository from your template (https://github.com/JetBrains/intellij-platform-plugin-template)
- in Project Structure, I've set the project SDK to IntelliJ IDEA Community Edition IC-232.10227.8
- my main module is also set up to use the same SDK (please see attached screenshots)
- i have commented out everything except for the java, kotlin, and gradle intellij plugin in my build.gradle.kts thinking that there may be an issue with it

When I run the "Run Plugin" gradle task, which should be :runIde, I get an error -> "Unresolved reference: PsiJavaFile". There's nothing red in the editor, the file was imported just fine. Autocomplete worked on it, but it just won't compile.

What am I missing?

Logs Upload ID: https://uploads.jetbrains.com/browse#2023_11_22_JYnhcsFXKa6nVB4GmiFspB

0

Hi,

Please share full Gradle build script and plugin.xml files.

1

Hello, Karol.

Arina made the post for me since I posted in the wrong section, my bad.

Here's the build.grade.kts

//import org.jetbrains.changelog.Changelog
//import org.jetbrains.changelog.markdownToHTML
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
plugins {
   id("java") // Java support
   alias(libs.plugins.kotlin) // Kotlin support
   alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
//    alias(libs.plugins.changelog) // Gradle Changelog Plugin
//    alias(libs.plugins.qodana) // Gradle Qodana Plugin
//    alias(libs.plugins.kover) // Gradle Kover Plugin
}
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()
// Configure project's dependencies
repositories {
   mavenCentral()
}
// Dependencies are managed with Gradle version catalog - read more: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog
dependencies {
//    implementation(libs.annotations)
   implementation("org.jetbrains:marketplace-zip-signer:0.1.8")
}
// Set the JVM language level used to build the project. Use Java 11 for 2020.3+, and Java 17 for 2022.2+.
kotlin {
   @Suppress("UnstableApiUsage")
   jvmToolchain {
       languageVersion = JavaLanguageVersion.of(17)
       vendor = JvmVendorSpec.JETBRAINS
   }
}
// Configure Gradle IntelliJ Plugin - read more: https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html
intellij {
   pluginName = properties("pluginName")
   version = properties("platformVersion")
   type = properties("platformType")
   // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
   plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
}
//// Configure Gradle Changelog Plugin - read more: https://github.com/JetBrains/gradle-changelog-plugin
//changelog {
//    groups.empty()
//    repositoryUrl = properties("pluginRepositoryUrl")
//}
//
//// Configure Gradle Qodana Plugin - read more: https://github.com/JetBrains/gradle-qodana-plugin
//qodana {
//    cachePath = provider { file(".qodana").canonicalPath }
//    reportPath = provider { file("build/reports/inspections").canonicalPath }
//    saveReport = true
//    showReport = environment("QODANA_SHOW_REPORT").map { it.toBoolean() }.getOrElse(false)
//}
//
//// Configure Gradle Kover Plugin - read more: https://github.com/Kotlin/kotlinx-kover#configuration
//koverReport {
//    defaults {
//        xml {
//            onCheck = true
//        }
//    }
//}
tasks {
   wrapper {
       gradleVersion = properties("gradleVersion").get()
   }
//    patchPluginXml {
//        version = properties("pluginVersion")
//        sinceBuild = properties("pluginSinceBuild")
//        untilBuild = properties("pluginUntilBuild")
//
//        // Extract the <!-- Plugin description --> section from README.md and provide for the plugin's manifest
//        pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
//            val start = "<!-- Plugin description -->"
//            val end = "<!-- Plugin description end -->"
//
//            with (it.lines()) {
//                if (!containsAll(listOf(start, end))) {
//                    throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
//                }
//                subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
//            }
//        }
//
//        val changelog = project.changelog // local variable for configuration cache compatibility
//        // Get the latest available change notes from the changelog file
//        changeNotes = properties("pluginVersion").map { pluginVersion ->
//            with(changelog) {
//                renderItem(
//                    (getOrNull(pluginVersion) ?: getUnreleased())
//                        .withHeader(false)
//                        .withEmptySections(false),
//                    Changelog.OutputType.HTML,
//                )
//            }
//        }
//    }
   // Configure UI tests plugin
   // Read more: https://github.com/JetBrains/intellij-ui-test-robot
   runIdeForUiTests {
       systemProperty("robot-server.port", "8082")
       systemProperty("ide.mac.message.dialogs.as.sheets", "false")
       systemProperty("jb.privacy.policy.text", "<!--999.999-->")
       systemProperty("jb.consents.confirmation.enabled", "false")
   }
   signPlugin {
       certificateChain = environment("CERTIFICATE_CHAIN")
       privateKey = environment("PRIVATE_KEY")
       password = environment("PRIVATE_KEY_PASSWORD")
   }
   publishPlugin {
       dependsOn("patchChangelog")
       token = environment("PUBLISH_TOKEN")
       // The pluginVersion is based on the SemVer (https://semver.org) and supports pre-release labels, like 2.1.7-alpha.3
       // Specify pre-release label to publish the plugin in a custom Release Channel automatically. Read more:
       // https://plugins.jetbrains.com/docs/intellij/deployment.html#specifying-a-release-channel
       channels = properties("pluginVersion").map { listOf(it.split('-').getOrElse(1) { "default" }.split('.').first()) }
   }
}

And here's the plugin.xml, it's pretty scarce.

<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
   <id>com.github.mijamarko.apiforge</id>
   <name>API Forge</name>
   <vendor>mijamarko</vendor>

   <depends>com.intellij.modules.platform</depends>
   <!-- Description of the plugin displayed on the Plugin Page and IDE Plugin Manager.
            Simple HTML elements (text formatting, paragraphs, and lists) can be added inside of <![CDATA[ ]]> tag.
            Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-description -->
   <description> Fast API development and data mocking for your Spring Boot applications. Make requests right from IntelliJ Idea </description>
   <extensions defaultExtensionNs="com.intellij">
       <toolWindow factoryClass="com.github.mijamarko.apiforge.window.MainWindowFactory" id="API Forge"/>
       <postStartupActivity implementation="com.github.mijamarko.apiforge.activities.ProjectOpenedActivity"/>
   </extensions>

</idea-plugin>
 

Please let me know if you need anything else.

Thanks!
 

0

Hi Marko,

What plugins do you depend on? I mean platformPlugins - please share gradle.properties file too.

0

Hello again,

This is what it looks like. No platform plugins specified, basically a barebones gradle.properties file.

Now that I read the comments in the file it looks like I'm supposed to specify exactly which plugins I need, correct? So, in my case, that would be something like com.intellij.psi? Any way to automate adding plugins to the platformPlugins property at compile time?

Thanks

# IntelliJ Platform Artifacts Repositories -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup = com.github.mijamarko.apiforge
pluginName = apiforge
pluginRepositoryUrl = https://github.com/mijamarko/apiforge
# SemVer format -> https://semver.org
pluginVersion = 0.0.1
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 223
pluginUntilBuild = 233.*
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
platformVersion = 2022.3.3
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins =
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 8.4
# Opt-out flag for bundling Kotlin standard library -> https://jb.gg/intellij-platform-kotlin-stdlib
kotlin.stdlib.default.dependency = false
# Enable Gradle Configuration Cache -> https://docs.gradle.org/current/userguide/configuration_cache.html
org.gradle.configuration-cache = true
# Enable Gradle Build Cache -> https://docs.gradle.org/current/userguide/build_cache.html
org.gradle.caching = true
# Enable Gradle Kotlin DSL Lazy Property Assignment -> https://docs.gradle.org/current/userguide/kotlin_dsl.html#kotdsl:assignment
systemProp.org.gradle.unsafe.kotlin.assignment = true
0

PsiJavaFile is a part of the Java plugin, so you should add a dependency on it. I don't know why it was not reported as an error in the editor, but the compilation error is correct. Maybe there was an editor glitch. You can try invalidating caches by triggering the File | Invalidate Caches… action.

In gradle.properties, you should define: platformPlugins = com.intellij.java.

In plugin.xml add <depends>com.intellij.java</depends>.

For more information about adding a plugin dependency, see: https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html

0

Yep, just added it myself a minute ago and now I'm feeling very stupid.

I've also added the <depends>com.intellij.java</depends> to my plugin.xml → is that overkill?

Sorry for the trouble, first time using gradle after maven.

0

I've also added the <depends>com.intellij.java</depends> to my plugin.xml → is that overkill?

No, it is required so that your plugin sees Java plugin classes at runtime.

You are welcome to ask questions. Consider using our community Slack in the beginning. The link is on this page: https://plugins.jetbrains.com/docs/intellij/getting-help.html

0

Thank you very much, Karol.

All the best,

Marko Mijajlović

0

请先登录再写评论。