When I build my project from IntellijIdea I get the following errors
Error:scalac: 'jvm-11' is not a valid choice for '-target'
Error:scalac: bad option: '-target:jvm-11'
I am using gradle to build my project. My project is using java 11 and scala 2.12.8.
Can someone help me resolve this error?
Scala 2.12 doesn't support JVM 11 as a target. You need to add this to your gradle build file:
tasks.withType<ScalaCompile> {
targetCompatibility = "1.8"
}
As for Scala 2.13, the fix for this issue is:
tasks.withType<ScalaCompile>() {
targetCompatibility = ""
scalaCompileOptions.additionalParameters = listOf("-target:11")
}
In my case, I simply had Scala misconfigured after Idea update.
Scala 12 can in fact be compatible with Java 11. It's better to check compatibility table.
I had to remove my previous Scala library from Project Structure and re-added it as described in this answer.
This is due to a bug in IntelliJ (or IntelliJ's Scala plugin):
https://youtrack.jetbrains.com/issue/SCL-18813
I have posted there a workaround, which was inspired by IvanoBulo's answer above.
Related
I'm (almost) a beginner in plugin creation (I created one a long time ago) and I would like to create a plugin that works BOTH with IntelliJ and with Android Studio (this to start with, because later I would like it to work also for Webstorm, PyCharm...).
The principle of my plugin is to use the parsing provided by IntelliJ (for Java for the moment, later for Kotlin, PHP...) thanks to the PSI (I MUST use PSI!). I've spent days reading and testing information at https://plugins.jetbrains.com/docs/intellij , https://plugins.jetbrains.com/docs/intellij/android-studio.html (and so on) and online tutorials, but I still can't configure my project (even before coding it).
Can you help me?
Here are some information:
I created the plugin ('empty' plugin for now) from the github template presented the online documentation. No problem for that.
I use a JDK 11. I guess this is what I have to do now (unlike before when I had to use the IntelliJ JDK).
I want to code my plugin in Java (not in Kotlin). The template generated Kotlin code (MyBundle.kt, listeners, services...) but I don’t need these Kotlin files. What to write to replace this code in Java ?
I don't know Kotlin (or very very little) and I usually develop in Java with Android Studio and Gradlen and I want to keep the build.gradle.kst (better than build.gradle).
I must also use a personal .jar file (not a lib like JSON for instance) for my plugin to work. Do I only have to add this jar in the libraries of the 'project settings' or do I have to do something else?
Here is my current configuration (most interesting parts):
plugin.xml (with error)
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.java-capable</depends> // correct ?
<depends>com.intellij.modules.androidstudio</depends> // error : cannot resolve plugin in dependencies
<depends>org.jetbrains.android</depends> // error : cannot resolve plugin in dependencies
build.gradle.kts (with questions)
plugins {
// Java support
id("java")
// Gradle IntelliJ Plugin
id("org.jetbrains.intellij") version "1.4.0"
// Gradle Changelog Plugin
id("org.jetbrains.changelog") version "1.3.1"
// Gradle Qodana Plugin
id("org.jetbrains.qodana") version "0.1.13"
}
...
configurations {
create("externalLibs")
}
dependencies {
// to integrate my personal jar file , correct ?
"externalLibs"(files("lib/myfile.jar"))
// to integrate an external API , correct ?
implementation("com.foo.api-java-sdk:1.0.2")
}
gradle.properties (with questions)
# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
pluginSinceBuild = 211
pluginUntilBuild = 213.*
# IntelliJ Platform Properties -> https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
platformType = IC
#platformVersion = 2021.1.3
platformVersion = 211.7628.21 // to be compatible between IJ and Android Studio, OK ?
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = com.intellij.java, org.jetbrains.android // is it correct ????
# Java language level used to compile sources and to generate the files for - Java 11 is required since 2020.3
javaVersion = 11
# Gradle Releases -> https://github.com/gradle/gradle/releases
gradleVersion = 7.4
If someone could give me the right configuration for all these files, it would be fine because I am totally lost and hopeless :-(
Thank you.
I use sourceCompatibility = 1.7 in gradle.properties, Gradle JVM(Settings, Gradle, Intellij IDEA) is 1.8.0_171 and
wrapper {
gradleVersion = '5.3'
distributionType = 'ALL'
}
in build.gradle.
When I run build task(Tasks->build->build Intellij IDEA) I get "error: incompatible types: inferred type does not conform to equality constraint(s)" during compileJava task.
If I set up Gradle JVM is 1.7.0_80 and
wrapper {
gradleVersion = '4.3'
distributionType = 'ALL'
}
build is fine.
What I'm doing wrong? How can I build JAVA 7 project using gradle 5.3?
This is probably caused by a subtle change in the type-checking rules for generics between Java 7 & Java 8 as described in Why does this program compile with Java 7 but not Java 8?
So what is the solution?
I doubt you will find a magic compiler switch or something to just make it work. Realistically, I think that your choices are:
You could just compile on a Java 7 platform as you did to start with. But this is not a good long-term solution.
If this is a supported product, lodge a support request.
If this is an open source product, check the product's issue checker to see if someone has already reported the problem. They may have reported a fix as well.
Look at the source code that you are trying to compile, identify the cause of the compilation error and fix it. If this is an open source product, submit your fix as a patch.
Note that it is possible that these compilation errors are reporting a latent bug that could under some circumstances lead to unexpected runtime exceptions.
You said:
I thought sourceCompatibility = 1.7 will set up java 7 for compile *.java.
It does. However, there are degrees of compatibility.
When you run a Java 8 compiler with -source 1.7 you are actually just turning off support for new language features. Under the hood, the compiler is still a Java 8 compiler. If there have been subtle changes in (for example) the type checker, it is plausible that the Java engineers did not implement a backwards compatibility mode for the old behavior.
(The extra mode may make an already complex piece of software too difficult to maintain. Type checking and type inference is one of the more difficult aspects of compiler implementation.)
On the following 'complie' in my Gradle file:
dependencies {
compile 'com.android.support:support-v4:25.3.1'
}
I have got the following error:
*All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found
versions 25.3.1, 24.0.0. Examples include
com.android.support:support-compat:25.3.1 and
com.android.support:animated-vector-drawable:24.0.0.
There are some
combinations of libraries, or tools and libraries, that are
incompatible, or can lead to bugs. One such incompatibility is
compiling with a version of the Android support libraries that is not
the latest version (or in particular, a version lower than your
targetSdkVersion.)*
But I don't find any use reference to this 'animated-vector-drawable' library in my project (used the search tool).
Any idea how to solve this problem?
Thanks !
Just add this line your app gradle file
compile 'com.android.support:animated-vector-drawable:25.3.1'
you need to set all gradle version should be same version
This question already has an answer here:
Sonarqube Analysis org.joda.convert ERROR
(1 answer)
Closed 6 years ago.
While running the SonarQube Gradle plugin on our project, during the Java Main Files AST scan, we're getting a number of warnings about joda-convert:
[WARN] [org.sonarqube.gradle.SonarQubeTask] Class not found: org.joda.convert.FromString
[WARN] [org.sonarqube.gradle.SonarQubeTask] Class not found: org.joda.convert.ToString
I've tried several ways of pulling in org.joda:joda-convert:1.8 and none of them have solved the problem. How can we figure out why this dependency is not being found?
Note: we're using Java JDK 1.8, Gradle 2.11, and SonarQube 5.3.
EDIT: this is the relevant snippet from build.gradle. I've tried joda-convert versions 1.7, 1.8, and 1.8.1 with no success.
buildscript {
repositories {
maven {
url "http://artifactory:7980/artifactory/libs-release"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:1.2"
classpath 'org.joda:joda-convert:1.7'
}
}
apply plugin: 'org.sonarqube'
sonarqube {
properties {
property "sonar.projectName", "Project"
property "sonar.projectKey", "local.project"
}
}
Joda time has two packages, joda-time and Joda-Convert. The annotations you are not able to find are in the Joda-Convert package, not [joda-time].
These errors are just low-severity warnings and should not actually affect your issues with using joda-time.
However, upon a second read-through of your question, it looks like you've already realized this and have included the dependency in your .gradle file. This suggests to me that most likely it's a configuration syntax issue with your .gradle file. If the first paragraph doesn't solve your issue, then please edit your question to include a .gradle snippet about how you've tried to include this dependency to fix the problem. Please note that Joda-time has Joda-convert as an optional dependency in its Maven POM and that could be confusing Gradle.
Also please include the versions of both joda-time and joda-convert you are attempting to use when you edit your question.
When I create a new "Grails Project" in GGTS-3.3.0 with Grails 2.3, I get several errors in ForkedTomcatServer.groovy. These are the errors I get:
Groovy:[Static type checking] - No such property: version for class:
org.codehaus.groovy.grails.plugins.GrailsPluginInfo ForkedTomcatServer.groovy /testapp/.link_to_grails_plugins/tomcat-7.0.42/src/groovy/org/grails/plugins/tomcat/fork line
165
Groovy:[Static type checking] - No such property: descriptor for
class:
org.codehaus.groovy.grails.plugins.GrailsPluginInfo ForkedTomcatServer.groovy /testapp/.link_to_grails_plugins/tomcat-7.0.42/src/groovy/org/grails/plugins/tomcat/fork line
166
These are the lines of code referenced in the errors:
GrailsPluginInfo info = GrailsPluginUtils.getPluginBuildSettings().getPluginInfoForName('tomcat')
String jarName = "grails-plugin-tomcat-${info.version}.jar"
File jar = info.descriptor.file.parentFile.listFiles().find { File f -> f.name.equals(jarName) }
I have not made any changes whatsoever. I just clicked File -> New -> Grails Project and the output has these errors. I have made several different projects and they all generate the same way.
Why is this happening and how can I fix it?
To fix this issue you should install Groovy 2.1. In GGTS the Groovy 2.1 is available from the dashboard. This solved my the problem.
From 2.3.0 Latest News updated yesterday
We are aware that the IDEs will require some updates to work with
Grails 2.3.0. If you plan to use 2.3.0 soon, please use the Intellij
IDEA EAPs and latest GGTS milestone releases which include updates to
work with Grails 2.3.0
I have the same issue to use Grails 2.3.0 with GGTS 3.3.0. After I installed the Groovy 2.1 from dashboard, this problem is gone. The same issue of the compiler version mismatch is also gone after install the latest Groovy
Workaround. Open ForkedTomcatServer.groovy, comment out the #CompileStatic, save file. The error will disappear. Now you can go ahead and un-comment that line and the error is gone. Groovy magic!
I also had this issue. Installtion of the Groovy 2.1 compiler sorted that out.
One of my errors said my workspace did not match the project and I could right-click and Eclipse fixed that part. Real issue was that I needed to update my compiler to 2.1.