Kotlin incompatible when creating Micronaut command line applications - kotlin

Whenever I attempt to create a command line app with Micronaut and Kotlin using:
mn create-cli-app cli2 --features kotlin
I get the following warning:
| Warning The following features are incompatible with other feature selections and have been removed from the project
| kotlin
The generated project has fallen back to Java, which is very graceful.
Is this a "bug" or current expected behaviour?

For selecting the language (java, groovy or kotlin) it is better to use the --lang flag instead of --features.
Doing:
$ mn create-cli-app mycli --lang=kotlin
| Generating Kotlin project...
| Application created at /tmp/mycli
Works as expected.

Related

Cannot create Groove Script on Intellij - Argument for #NotNull parameter

I am trying to start learning Groovy for perform API calls using ScriptRunner on JIRA. So I am starting from the basics.
My problem is that I cannot even create a Groovy script using Intellij. At the project creation it am selecting Groovy and choosing for project SDK version 16.0.2 and Groovy Library groovy-3.0.8
Once the project is created and I try to create the script, the IDE send me the following error message:
Argument for #NotNull parameter 'rootTypes' of com/intellij/openapi/roots/impl/ProjectFileIndexImpl.isUnderSourceRootOfType must not be null
Does anyone know why I am getting this error message?

Can't get kotlin "hello world" example to Run in intelliJ

I'm following the intelliJ IDEA tutorial titled Create your first Kotlin application
(Last modified: 08 March 2021). Here are the various versions I'm using:
~$ java -version
java version "16" 2021-03-16
Java(TM) SE Runtime Environment (build 16+36-2231)
Java HotSpot(TM) 64-Bit Server VM (build 16+36-2231, mixed mode, sharing)
~$ javac -version
javac 16
Here's my code:
fun main(args: Array<String>) {
println("What is your name?")
val name = readLine()
println("Hello $name")
}
Here's what my project structure looks like:
I notice that it says "Kotlin not configured" above my code, but when I go to Tools > Kotlin > Configure Kotlin in Project, I get
:
In the Event Log pane, I see this:
4/15/21
1:54 PM Download pre-built shared indexes
Reduce the indexing time and CPU load with pre-built JDK shared indexes
Always download
Download once
Don't show again
Configure...
1:54 PM Gradle sync started
1:54 PM Gradle sync failed: Unsupported class file major version 60 (5 s 329 ms)
1:55 PM No IDE or plugin updates available
In the Problems(?) pane, I see this:
Unresolved reference: println
Unresolved reference: readLine
Unresolved reference: println
Parameter 'args' is never used
Package directive doesn't match file location
Any ideas on why the basic functions in my program are not recognized?
Thanks for looking!
Edit: I tried downloading JDK 15 and specifying that in my Project Structure, but I got the same results:
try build>clean project.
As for your unresolved references, you can double-click/left-click > show context options. If that doesn't work then maybe reinstall InteliJ Idea or download Android Studio which has a lot more support on google and yt.
Okay, I got it working. I'll try to figure out what I did.
tldr; I had to switch from JDK 16 to JDK 15 to get my hello world console application to run.
First, when I was setting up the project, I chose the wrong Project Template: I selected JVM - Application rather than JVM - Console Application. This is what I needed to do:
So, I started a new project, chose the right template, and I typed in my code, and I noticed a Build pane at the bottom left displayed:
I tried Build > Build Project, and nothing changed. So, I tried the Run menu item: the first section of the Run menu was grayed out, but there was another Run command in the second section of the Run menu. I selected that Run, and a little window popped up with the following:
Run
0 Edit Configurations
The "0 Edit Configurations" line was highlighted, and I got nowhere trying to figure out how to Run my code.
So, I started yet another new project, and this time I selected a different JDK, version 15:
After clicking Next, then Finish, I typed in my code, and this time the Build pane looked like the following (without me doing anything but typing in my code):
After I finished typing in my code, as the tutorial described, this time there was a little green arrow in the gutter:
When I clicked on the green arrow in the gutter, I could successfully Run my program.
So, it appears that you cannot use JDK 16, and you have to use JDK 15. intelliJ was able to detect all my installed Java versions, so any version you have installed should appear as a choice in the the project settings. You may have to quit intelliJ, then restart intelliJ after you install JDK 15 in order to see it listed as a choice under Project JDK: when you create a project.

Kotlin - Error: Could not find or load main class _DefaultPackage

I followed the Kotlin tutorial for eclipse here : Getting Started With Eclipse Luna
However, I'm running into this error:
Error: Could not find or load main class _DefaultPackage
Anyone who knows to get around this?
This was a severe bug (KT-10221) in automatic generation of Launch Configuration in plugin version 0.4.0. It was fixed in 0.5.0 so the recommendend way to workaround is to update plugin.
The source of the problem was that the plugin used an old pattern for generating name of the class for main function that had been abandoned by Kotlin compiler.
It's possible to workaround it by editing launch configuration (Eclipse Menu -> Run -> Run Configurations...) by hand and changing Main class field in Java Application group. If the file is named hello.kt with no package directive, as it is described in tutorial, than corrected string should be HelloKt.
If file has name other.kt with package my.tutorial than the Main Class should contain my.tutorial.HelloKt. You can read more about it in the section Package-Level Functions of Calling Kotlin From Java page.
I have been getting the same issue. And after putting the right compiler output path, it got resolved.
Go to Project -> Project Compiler output :
In the text box, fill this:
[Absolute Path]/{Project Name}/out
In my case I was having this problem while trying to run the program using the Application Gradle plugin. The problem was in the mainClassName property using single quotes instead of double ones
This didn't work:
mainClassName = 'demo.HelloWorldKt'
With double quotes, it works:
mainClassName = "demo.HelloWorldKt"
For me it worked after I installed the correct JDK. I first had JDK 11 but the tutorial I did was with JDK 8 so after I installed this and set it in the "installed JREs" options it found the main class without having any "mainClassName" or any other option in the build.gradle file.
For me, it worked in a fresh eclipse workspace. Possibly, the Kotlin eclipse plugin is not playing well with other plugins (in my case, PyDev).
I'm creating a Kotlin Application with JavaFX and I had this issue until I went to:
Run > Run Configurations > Java Application > Common
I unticked "Allocate console" and it fixed the issue.

IDEA(Ultimate v.14.0) with scala plugin(v.1.1.1) do not compile test classes

Today I have updated the scala-plugin to v.1.1.1 in IDEA Ultimate v.14.0 and now I can't execute tests via IDEA.
I get an exception: java.lang.ClassNotFoundException: models.HelloWorldSpec
I noticed that test classes do not appears in 'target/scala-2.10/test-classes' after compilation via IDEA. But all good when I execute 'sbt clean compile test' in the console.
This is resolved in release 1.1.2 of the IntelliJ Scala plugin, as of 21st November:
https://plugins.jetbrains.com/update/index?pr=&updateId=17896

Quasiquotes in Intellij 14?

After installing the newly released IJ14 Community Edition - the quasiquotes (which had been working on IJ13) popped up on the radar.
Is there an IJ setting to enable this?
BTW this is a maven build (and works in 13.1 just fine!). Here is the section of the build related to the quasiquotes. I have not seen any mention of the plugin not working properly in 14, but input here would be appreciated.
<!-- The following plugin is required to use quasiquotes in Scala 2.10 and is used
by Spark SQL for code generation. -->
<compilerPlugins>
<compilerPlugin>
<groupId>org.scalamacros</groupId>
<artifactId>paradise_${scala.version}</artifactId>
<version>${scala.macros.version}</version>
</compilerPlugin>
</compilerPlugins>
UPDATE I just installed the 14.0.1 update from 11/11/14. This time I tried Intellij Ultimate : but Quasiquotes are still not working.
UPDATE I have opened a JIRA with JetBrains. https://youtrack.jetbrains.com/issue/IDEA-133993
I think there is a workaround to get it running:
You have to go to the IntelliJ settings, to the "Scala Compiler" and add a plugin: "/home/YOURUSERNAME/.m2/repository/org/scalamacros/paradise_2.10.4/paradise_2.10.4-2.0.1.jar"
The problem involves the paradise plugin that provides support for quasiquotes with scala 2.10. It is not working in IJ14 presently.
UPDATE The following is new info on the building with Spark page
https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark#ContributingtoSpark-IntelliJ
"Rebuild Project" can fail the first time the project is compiled, because generate source files are not automatically generated. Try clicking the "Generate Sources and Update Folders For All Projects" button in the "Maven Projects" tool window to manually generate these sources.
Compilation may fail with an error like "scalac: bad option: -P:/home/jakub/.m2/repository/org/scalamacros/paradise_2.10.4/2.0.1/paradise_2.10.4-2.0.1.jar". If so, go to Preferences > Build, Execution, Deployment > Scala Compiler and clear the "Additional compiler options" field. It will work then although the option will come back when the project reimports. If you try to build any of the projects using quasiquotes (eg., sql) then you will need to make that jar a compiler plugin (just below "Additional compiler options"). Otherwise you will see errors like:
/Users/irashid/github/spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
Error:(147, 9) value q is not a member of StringContext
Note: implicit class Evaluate2 is not applicable here because it comes after the application point and it lacks an explicit result type
q"""
^
It's s not q:
val x = 5.0
println(s"$x.toInt")
I loaded spark up in Intellij 13 and the macro paradise backport of quaisquotes still shows an error, I don't see how intellij would be able to support this syntax as it's a compiler plugin: