Can not find PsiClass in my Intellij plugin project - intellij-plugin

Many tutorials mention a class - PsiClass, but I can't find this class in my project.
My build.gradle as below:
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.16'
id 'org.jetbrains.kotlin.jvm' version '1.3.61'
id 'idea'
}
apply plugin: "org.jetbrains.intellij"
apply plugin: 'java'
apply plugin: 'idea'
group 'com.github.boybeak.adapter'
version '0.1'
sourceCompatibility = 1.8
repositories {
/*google()
jcenter()*/
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
// implementation group: 'com.github.boybeak', name: 'any-adapter', version: '1.1.2'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
intellij {
/*version '192.7142.36'*/
type 'AI'
plugins 'android'
localPath '/Applications/Android Studio.app'
}
My IDEA version:
IntelliJ IDEA 2019.3.1 (Community Edition)
Build #IC-193.5662.53, built on December 18, 2019
Runtime version: 11.0.5+10-b520.17 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.15.3
GC: ParNew, ConcurrentMarkSweep
Memory: 990M
Cores: 4
Registry:
Non-Bundled Plugins: DBN, OdpsStudio, no.tornado.tornadofx.idea
Should I add some more libraries in my project?

After a little more searching, I find a solution.
https://intellij-support.jetbrains.com/hc/en-us/community/posts/360005055559-Missing-classes-after-upgrade-to-2019-2-2
Change my Gradle like this:
intellij {
/*version '192.7142.36'*/
type 'AI'
plugins 'android', 'java'
localPath '/Applications/Android Studio.app'
}
Add Java plugin after android

Adding a Kotlin Script solution if you're using build.gradle.kts
intellij {
...
setPlugins("java")
}
The newest Idea Plugin template suggests gradle.properties as a source of plugin dependencies
// gradle.properties
platformPlugins = ...
// build.gradle.kts
val platformPlugins: String by project
intellij {
setPlugins(*platformPlugins.split(',').map(String::trim).filter(String::isNotEmpty).toTypedArray())
}

I was able to fix this by adding this to the build.gradle.kts file:
intellij {
version.set("2021.3.3")
type.set("IC") // Target IDE Platform
plugins.set(listOf("com.intellij.java")) // Add this
}
When I did that, this little guy popped up:
I clicked on that and then I was able to import the PsiClass.

Related

Build Intellij plugin in IDEA 2019.1 & 2020.3

Building for IDEA 2019.1 works like a charm! I thought that building for 2020.3 would be just a matter of pointing to 2020.3 installation folder and that's it, but it is not being even close to it.
That's my gradle.build
group 'com.test.plugin'
version '1.0-SNAPSHOT'
buildscript {
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
classpath group: 'org.jetbrains.intellij.plugins', name: 'gradle-intellij-plugin', version: '0.6.5'
}
}
apply plugin: 'java'
apply plugin: 'org.jetbrains.intellij'
intellij {
localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
}
sourceCompatibility = 1.8
repositories {
maven {
url "https://mydomain/repository/public-maven/"
}
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime group: 'com.google.guava', name: 'guava', version: '23.0'
runtime group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
}
It is important to mention that since I'm working behind a restricted company proxy I can't just set the Intellij version in order to get the necessary distribution files to the build (Intellij.localPath)
Building it on IDEA 2019.1, JDK 1.8 works fine. In order to build the same code for a IDEA 2020.3 I just replaced the Intellij distribution path:
intellij {
//localPath 'C:/Program Files/JetBrains/IntelliJ IDEA 2019.1.3'
localPath 'C:/Dev/apps/ideaIU-2020.3'
}
Trying to build it now immediately throws it:
error: cannot access AnAction
bad class file: C:\Dev\apps\ideaIU-2020.3\lib\platform-api.jar(com/intellij/openapi/actionSystem/AnAction.class)
class file has wrong version 55.0, should be 52.0
Please remove or make sure it appears in the correct subdirectory of the classpath.
What I understand form it is that AnAction class was built using Java 11. So, I replaced the project JDK to use also JDK11 and from that moment I started facing compilation errors, like com.intellij.psi.PsiJavaFile cannot be found.
I might be missing some conceptual point here.
it turns out there was a missing plugin dependency.
this line was not being effective to resolve such dependency. In order to fix that I had to remove apply plugin: 'java' and set intellij.plugin
intellij {
localPath 'C:/Dev/apps/ideaIU-2020.3'
plugin = ['com.intellij.java']
}

Declare a bundled plugin as a dependency in IntelliJ IDEA Plugin

Non bundled plugins are stored in the repository and can be referenced by groupId:artifactId:versionId but the documentation only says this ambiguous thing about declaring dependencies on bundled plugins:
locate the plugin’s main JAR file containing META-INF/plugin.xml
descriptor with tag (or if not specified).
Okay. Locate it and do what exactly?
My solution was to copy the template for a gradle IntelliJ plugin and copy this example which led me to declare the dependency by plugin name with no version, groupId. In my case I wanted to use classes from the built-in maven plugin so I added this to the plugins = [....]. The plugin will automatically grab the version of that plugin that is in your IntelliJ.
build.gradle
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.26'
}
group 'com.whatever'
version '1.0-SNAPSHOT'
id 'MyPlugin'
repositories {
mavenCentral()
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
runtime files('maven.jar', 'libs/gson-2.2.4.jar')
runtime fileTree(dir: 'libs', include: '*.jar')
}
// See https://github.com/JetBrains/gradle-intellij-plugin/
intellij {
version '2020.2.2'
plugins = ['maven']
}
patchPluginXml {
changeNotes """
Add change notes here.<br>
<em>most HTML tags may be used</em>"""
}

How to properly configure Kotlin plugin for Gradle?

I'm trying to build a basic Gradle project. My build.gradle file is below. I keep getting the below error. I don't get it because you can find the plugin here... where I think I'm directing to: https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-gradle-plugin
Update: same thing happens to the spring-boot plugin if I comment out the Kotlin line. It's not just specific to the Kotlin plugin.
The error:
Error:(21, 0) Plugin [id: 'kotlin', version: '1.1.1'] was not found in any of the following sources:
- Gradle Core Plugins (not a core plugin, please see https://docs.gradle.org/3.3/userguide/standard_plugins.html for available core plugins)
- Gradle Central Plugin Repository (no 'kotlin' plugin available - see https://plugins.gradle.org for available plugins)
Build.gradle:
buildscript {
ext.kotlin_version = '1.1.1'
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE")
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'java'
id 'kotlin' version "1.1.1"
id 'spring-boot'
}
group 'si.dime.kotlin.tutorials.rest'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile("org.springframework.boot:spring-boot-starter-web:1.3.3.RELEASE")
}
For non-core Gradle plugins (those that are not from the org.gradle namespace), you have to use a fully qualified id as well as a version number.
The official Kotlin documentation contains the id to use:
plugins {
id "org.jetbrains.kotlin.jvm" version "<version to use>"
}
(You can also find these ids by searching for the plugin on the plugins.gradle.org site.)

How to debug xtend code in IntelliJ + Gradle?

I have just started to learn Xtend (http://xtend-lang.org/) and try to write a small app in IntelliJ 2016 based on a Gradle project using the Xtext/Xtend 2.10.0 plugins from the standard repository. The problem is that I cannot debug my Xtend code. Breakpoints are all ignored although debugging of Java code works. Debugging Xtend code only works if I use the IntelliJ wizard and create a standard IntelliJ project without using Gradle. I don't know how to fix this? Do I miss something? Does debugging works different in a Gradle project?
Here my Gradle file:
group 'GradleXtend'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'org.xtext.xtend'
sourceCompatibility = 1.5
repositories {
jcenter()
mavenCentral()
}
dependencies {
compile 'org.eclipse.xtend:org.eclipse.xtend.lib:2.10.0'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.xtext:xtext-gradle-plugin:1.0.12'
}
}
xtend {
debugger {
//how to install debug info into generated Java code
//SMAP adds Xtend debug info on top of Java
//PRIMARY makes Xtend the only debug info (throws away Java line numbers)
//default is SMAP for Java projects and PRIMARY for Android
sourceInstaller = 'SMAP' //or 'PRIMARY' or 'NONE'
//whether to hide synthetic variables in the debugger
hideSyntheticVariables = false
}
}
My Xtend file:
package HelloWorld
class HelloWorld2 {
def static void main(String[] args) {
println("Hello")
}
}

Gradle dependencies in Idea project

I'm trying to use Gradle, but Idea dont see dependices. Here is my build.gradle
group 'me.ozka'
version '1.0.1'
buildscript {
ext.kotlin_version = '1.0.3'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'java'
apply plugin: 'kotlin'
sourceCompatibility = 1.5
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile group: 'junit', name: 'junit', version: '4.11'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.20'
compile 'org.eclipse.jetty:jetty-server:9.0.0.RC2'
compile 'org.eclipse.jetty:jetty-servlet:9.0.0.RC2'
}
When i'm trying import import org.eclipse.jetty.server.Server; Idea signal me an error. What i'm doing wrong?
upd: i'm also don't see jar files in Idea External library folder.
upd2: i'm add to build file apply plugin: 'jetty' and it's solve my problem!
You need to refresh your gradle dependencies.
Here are some ways of doing this.
Approach 1 (GUI):
Go to View -> Tool Windows -> Gradle
Click on the big refresh button (Refresh all gradle projects).
Approach 2 (Command):
gradle build --refresh-dependencies