Build Intellij plugin in IDEA 2019.1 & 2020.3 - intellij-plugin

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']
}

Related

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>"""
}

Can not find PsiClass in my Intellij plugin project

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.

TornadoFX unresolved JavaFx

I wanted to create a new project that should be a desktop application. For this purpose, I have selected Kotlin language and TornadoFX framework. I have installed the TornadoFXplugin and created a new Ttornadofx-gradle-project. The base setup made by Intellij was successful but I have encountered a problem. When I wanted to run the generated project it failed. The project cannot resolve the java fx. I have dug through the web and found nothing that would fix the problem. The error log that I receive after the failed build is:
HAs anyone faces the same issue? How can I get rid of it?
I have installed the JDK 11 and set it up to the build config and I still receive the problem:
java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Is there a change that I have missed something in the middle?
It looks like you are running the TornadoFX project with Java 11 or 12.
It also looks like the TornadoFX plugin is intended for Java 1.8, but it is not advised what to do with Java 11+.
Since Java 11, JavaFX is no longer part of the JDK.
You can read all about getting JavaFX as a third party dependency into your project here: https://openjfx.io/openjfx-docs/, and since you are using Gradle, this section will be helpful: https://openjfx.io/openjfx-docs/#gradle.
I've just installed the Tornado plugin, and created a project, using JDK 12.0.1. I've also updated the gradle-wrapper.properties file to use Gradle 5.3-bin as the default 4.4 doesn't work with Java 11+.
If I run it, I get the same errors:
e: /.../src/main/kotlin/com/example/demo/app/Styles.kt: (3, 8): \
Unresolved reference: javafx
e: /.../src/main/kotlin/com/example/demo/app/Styles.kt: (18, 13): \
Cannot access class 'javafx.scene.text.FontWeight'. Check your module classpath for missing or conflicting dependencies
...
Basically these errors indicate that JavaFX is not found. The Tornado plugin wasn't expecting this.
Solution
There is an easy solution to make this work: add the JavaFX gradle plugin to the build, so it deals with the JavaFX part.
According to the plugin's repository, all you need to do is edit the build.gradle file and add:
buildscript {
ext.kotlin_version = "1.2.60"
ext.tornadofx_version = "1.7.17"
ext.junit_version = "5.1.0"
repositories {
mavenLocal()
mavenCentral()
maven {
setUrl("https://plugins.gradle.org/m2/")
}
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.1.0"
// Add JavaFX plugin:
classpath 'org.openjfx:javafx-plugin:0.0.7'
}
}
apply plugin: "kotlin"
apply plugin: "application"
apply plugin: "org.junit.platform.gradle.plugin"
// Apply JavaFX plugin:
apply plugin: 'org.openjfx.javafxplugin'
// Add the JavaFX version and required modules:
javafx {
version = "12.0.1"
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
...
And this is it, refresh your project, the IDE should recognize all the JavaFX classes.
If you modify the default MainView.kt like:
class MainView : View("Hello TornadoFX \n with JavaFX "
+ System.getProperty("javafx.version")) {
override val root = hbox {
label(title) {
addClass(Styles.heading)
}
}
}
you should be able to run it:
This answer is for those who wish to use Gradle Kotlin DSL.
An example of minimal build.gradle.kts:
plugins {
kotlin("jvm") version "1.4.0-rc"
application
id("org.openjfx.javafxplugin") version "0.0.9"
}
application { mainClassName = "com.example.MyApp" }
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/kotlin/kotlin-eap")
}
dependencies {
// Kotlin standard library
implementation(kotlin("stdlib-jdk8"))
// TornadoFX dependency
implementation("no.tornado:tornadofx:1.7.20")
}
// JavaJX module to include
javafx { modules = listOf("javafx.controls", "javafx.fxml", "javafx.graphics") }
// Set Kotlin/JVM target versions
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions.jvmTarget = "11" // or higher
kotlinOptions.languageVersion = "1.4"
}
// Be sure to use lates Gradle version
tasks.named<Wrapper>("wrapper") { gradleVersion = "6.6" }
For a full working example, check out GitHub repository
Please note that it also works with JDK 13 and 14
i'm recieved this error when download Kodein-Samples and trying to run tornadofx sample under Java11/12 and JavaFX13.
java.lang.UnsupportedClassVersionError: org/openjfx/gradle/JavaFXPlugin has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
The solution was is quite simple: i'm only comment another modules in settings.gradle (because the error occurred in some other module). Unfortunately, after the launch the application generates an error when trying to edit the record. I haven't dealt with it yet.
so my build.gradle.kts looks like this:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val kodeinVersion: String by rootProject.extra
plugins {
kotlin("jvm")
application
id("org.openjfx.javafxplugin") version "0.0.8"
}
repositories {
jcenter()
maven(url = "https://dl.bintray.com/kodein-framework/Kodein-DI/")
}
application {
mainClassName = "org.kodein.samples.di.tornadofx.KodeinApplication"
}
javafx {
version = "13"
modules = mutableListOf("javafx.controls", "javafx.fxml", "javafx.base", "javafx.media")
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
implementation("no.tornado:tornadofx:1.7.19")
implementation("org.kodein.di:kodein-di-generic-jvm:$kodeinVersion")
implementation("org.kodein.di:kodein-di-conf:$kodeinVersion")
implementation("org.kodein.di:kodein-di-framework-tornadofx-jvm:$kodeinVersion")
}
i made fork for this example with changes: https://github.com/ibelozor/Kodein-Samples

IntelliJ Idea 16 CE gradle issues

In my gradle file I am trying to use the following to solve another issue. This is my gradle file:
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
task copyDependenciesToTarget(type: Copy) {
println 'Copying dependencies to target...'
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
}
build.dependsOn(copyDependenciesToTarget)
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
The problem are is this:
configurations.compile.collect().each { compileDependency ->
copy {
with from (compileDependency.getPath()) {
include '*'
}
into 'target/libs/libs'
}
}
When I run the application I get this Exception:
org.gradle.api.internal.file.copy.CopySpecWrapper_Decorated cannot be cast to org.gradle.api.internal.file.copy.CopySpecInternal
Main problem is, I have no idea how to fix this error, I simply want my project to create a JAR file that works with JDBC, using this gradle code seems to be a solution for that issue, but now I have run into another problem, yet again.
Please let me know if you require any additional information and thank you in advance. Literally, I cant even. This problem.
EDIT
As stated in the comments. My project runs fine when I run it through the IDE. There is an issue when I create a JAR file using gradle. The bare gradle file that IntelliJ created when I started the gradle project follows (Added the jar config so my Main class would be picked up):
group 'com.winapp'
version '1.0-SNAPSHOT'
apply plugin: 'java'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'src/main/java/libs', include: ['*.jar'])
compile 'com.intellij:forms_rt:6.0.5'
testCompile group: 'junit', name: 'junit', version: '4.11'
}
jar {
manifest.attributes(
"Main-Class": "Main",
"Class-Path": configurations.compile.collect { 'libs/' + it.getName()}.join(' ')
)
}
When I execute my app from terminal after the JAR has been created (keeping in mind there are no issues when hitting run in the IDE) with java -jar myAppName.jar:
java.lang.ClassNotFoundException: org.sqlite.JDBC
NOTE: Usually I get a full stack running a java app, but in this case the above is the only output.
I am using this JAR for my sqlite needs:
sqlite-jdbc-3.15.1
As a test I commented out the Sqlite usage in my application and the JAR file worked fine. My GUI was displayed and everything went as expected (all things considered). The JAR stops working when I add the sqlite JAR file usage (code). Added it the same as my other libs (like retrofit), so this seems to be quite a strange issue.
Please let me know if I have explained the issue correctly?

Automatically download sources in Gradle project

In Maven projects, there is an option to automatically download sources (and javadoc) for all libraries. For Gradle project I found no option, just to open a class and click "Search in internet". This is very annoying if you have a lot of libraries. Is there any way to automatically attach sources from the internet (maven repo)?
I know that this is an old topic, but in case someone reaches here and does not want to gradle idea, you can also use a plugin and then it will resolve sources automatically.
e.g. both idea and eclipse compatible build.gradle
plugins {
id "java"
id "idea"
id "eclipse"
}
idea {
module {
downloadSources = true
}
}
eclipse {
classpath {
downloadSources = true
}
}
dependencies {
compile group: 'commons-io', name: 'commons-io', version: '2.6'
}