How to debug xtend code in IntelliJ + Gradle? - intellij-idea

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

Related

"Could not find method wrapper()" in build.gradle file generated by openapi-generator kotlin client

I have a simple spring boot project using the kotlin gradle dsl. I want to generate an OpenApi client using the openapi client generator gradle Plugin. I have successfully done so, using this configuration. Until now, this was a single project build. But when i try to include it, i get an error message "Could not find method wrapper()".
This is how i generated the client and added it's file into my source sets:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.springframework.boot") version "3.0.2"
id("io.spring.dependency-management") version "1.1.0"
kotlin("jvm") version "1.7.22"
kotlin("plugin.spring") version "1.7.22"
id("org.openapi.generator") version "6.3.0"
}
// other dependencies
openApiGenerate {
generatorName.set("kotlin")
inputSpec.set("src/main/openapi/my-api.yml")
outputDir.set("$buildDir/generated/my-api")
packageName.set("com.myapi")
}
kotlin.sourceSets["main"].kotlin.srcDir("$buildDir/generated/my-api/src/main/kotlin")
Now i want to use this generated client in my project. It comes with it's own build.gradle (in groovy) which loads the necessary dependencies etc.
I have modified my settings.gradle.kts file accordingly:
rootProject.name = "myapp"
include("build:generated:my-api")
When i reload gradle, i get the follwing error:
> Could not find method wrapper() for arguments [build_gdswinwcvulw9afq79kj4v6h$_run_closure1#582f32f7] on project ':build:generated:my-api' of type org.gradle.api.Project.
This is due to the build.gradle file generated by the generator looking like this:
group 'org.openapitools'
version '1.0.0'
wrapper {
gradleVersion = '7.5'
distributionUrl = "https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip"
}
buildscript {
ext.kotlin_version = '1.7.21'
repositories {
maven { url "https://repo1.maven.org/maven2" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'maven-publish'
repositories {
maven { url "https://repo1.maven.org/maven2" }
}
test {
useJUnitPlatform()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "com.squareup.moshi:moshi-kotlin:1.13.0"
implementation "com.squareup.moshi:moshi-adapters:1.13.0"
implementation "com.squareup.okhttp3:okhttp:4.10.0"
testImplementation "io.kotlintest:kotlintest-runner-junit5:3.4.2"
}
I am using Gradle 7.6 and i am a bit out of ideas here since i am pretty new to Gradle.

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

How to make idea plugin in gradle generate proper project configuration for Kotlin?

I have configured my build.gradle to run gradle test and gradle run properly. However, IDEA does not show any run/test tasks after importing the configuration generated by gradle idea. It seems that these tasks are not included at ipr/iws at all.
Here is my build.gradle:
buildscript {
ext.kotlin_version = '1.2.0'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
}
}
apply plugin: 'kotlin'
apply plugin: 'org.jetbrains.dokka'
apply plugin: 'application'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'idea'
dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}
sourceSets {
test.kotlin.srcDirs += 'src/test/kotlin'
}
junitPlatform {
enableStandardTestTask true
}
defaultTasks 'run'
mainClassName = 'simpledb.server.Startup'
repositories {
maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.2'
testRuntime (
'org.junit.jupiter:junit-jupiter-engine:5.0.2',
'org.junit.platform:junit-platform-launcher:1.0.2'
)
testCompile "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
}
I was wondering is there any way to make generated project configurations include these tasks(run/test)? I have also heard people saying Don't use gradle idea, so is it impossible to use gradle idea to implement this?
It is simply not necessary in your case. Just open the build.gradle file with IDEA and everything should be smooth. The idea Gradle plugin is somewhat deprecated. Not officially, but it was created by Gradle team and is not actively developed to adapt to new IDEA versions and features and so on. So if you don't need special customizations, just open the build.gradle with IDEA and you should be good to go.

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?

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