Kotlin compiler not found using Gradle plugin - gradle

I'm trying to upgrade some Gradle projects from Kotlin 1.0.6 to its latest version (1.1.0). However, whenever it reaches the compileKotlin task it fails:
:kiwi-common-kotlin:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':kiwi-common-kotlin:compileKotlin'.
> Could not find Kotlin Compiler jar. Please specify compileKotlin.compilerJarFile
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The project itself is divided in a bunch of subprojects. To avoid dupes, we have a separate file with the Kotlin definitions and import it on the projects using it:
File: gradle/kotlin.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
compileKotlin {
kotlinOptions.jvmTarget = "1.6"
}
And we import it in the subprojects like this:
apply from: "$rootDir/gradle/kotlin.gradle"
Since we previously tried the early preview releases and it worked seamlessly, I changed the version a couple times to see in which version the plugin broke. It turns out it works up to 1.1-M03; beginning at 1.1-M04 it shows the exact same error as in the 1.1.0 release.
We're using Gradle 2.10 in the project. Can you help me figure out whether it is a problem in our configuration? or a known issue with the Kotlin plugin itself?

It turned out to be a bug with the Gradle plugin. As pointed out by hotkeys' comment, updating to v1.1.2 fixes it.

Related

Gradle does not see a plugin that is on the plugin portal

Gradle 4.6 here. Trying to use markdown-gradle-plugin to convert markdown files into HTML as part of my build. My build.gradle specifies:
plugins {
id 'com.github.johnrengelman.shadow' version '4.0.4'
id 'java'
id 'edu.sc.seis.launch4j' version '2.4.6'
id 'org.kordamp.gradle.markdown' version '2.0.0'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
compile(
'ch.qos.logback:logback-classic:1.2.3'
... (all of my dependencies here)
)
}
... rest of my build.gradle here
When I run:
./gradlew clean markdownToHtml
I get:
$ ./gradlew clean markdownToHtml
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/myuser/workspace/myapp/build.gradle' line: 14
* What went wrong:
An exception occurred applying plugin request [id: 'org.kordamp.gradle.markdown', version: '2.0.0']
> Failed to apply plugin [id 'org.kordamp.gradle.markdown']
> Could not find method register() for arguments [markdownToHtml, class org.kordamp.gradle.plugin.markdown.tasks.MarkdownToHtmlTask, org.kordamp.gradle.plugin.markdown.MarkdownPlugin$1#3b46a8ba] on task set of type org.gradle.api.internal.tasks.DefaultTaskContainer.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
I can verify that I do see the 2.0.0 version of the plugin on the Gradle plugin portal.
Can anybody spot where I'm going awry?
According to the kordmap plugins website:
Java 8 and Gradle 5 are the minimum requirements to use any of these
plugins.
So your version of gradle needs an upgrade.
The error is coming from when the plugin attempts to use TaskContainer::register, which was introduced in gradle 4.9, so you might be safe to upgrade to version 4.9, but I'd suggest going with what the website says and bumping it to version 5.

Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not found in any of the following sources

I have a fresh install of IntelliJ, I created a new kotlin gradle project using the following settings:
This produces the following build.gradle.kts, (the exact same file works on my Windows machine):
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
Which produces this error, when trying to do a gradle refresh:
Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.71'] was not
found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.2.71')
Searched in the following repositories:
Gradle Central Plugin Repository
Check your Internet connection and make sure your Internet is not restricted.
I solved this problem by turning on proxy for all tunnels (not just HTTP) with a VPN app.
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
// kotlin("jvm") version "1.2.71"
}
group = "com.test"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
compile(kotlin("stdlib-jdk8"))
}
//tasks.withType<KotlinCompile> {
// kotlinOptions.jvmTarget = "1.8"
//}
gradle sync by commenting the above lines. The gradle will be set up.
once the gradle is downloaded, uncomment those line and sync again.
if the dependencies are not downloaded properly, run 'gradle build' in the terminal and click on gradle sync.
This solved the issue for me.
(1) in my case (OpenJDK 11 on Ubuntu 18.04) the problem was Gradle not being able to download the POM file from gradle plugin-server. you can test it by entering this line into jshell:
new java.net.URL("https://plugins.gradle.org/m2/org/jetbrains/kotlin/jvm/org.jetbrains.kotlin.jvm.gradle.plugin/1.3.11/org.jetbrains.kotlin.jvm.gradle.plugin-1.3.11.pom").openStream()
(you can find your url by running gradle with --debug option)
So if you received an exception like this: InvalidAlgorithmParameterException: trustAnchors parameter must be non-empty then the trouble is CA-certs cache. which could be easily fixed by writing these lines into bash Ref:
sudo su
/usr/bin/printf '\xfe\xed\xfe\xed\x00\x00\x00\x02\x00\x00\x00\x00\xe2\x68\x6e\x45\xfb\x43\xdf\xa4\xd9\x92\xdd\x41\xce\xb6\xb2\x1c\x63\x30\xd7\x92' > /etc/ssl/certs/java/cacerts
/var/lib/dpkg/info/ca-certificates-java.postinst configure
By the way do not forget to restart gradle daemon before trying again. (gradle --stop)
(2) another reason could be your internet not having access to bintray.com (the internet of Iran or China) which you can test by putting this line on jshell :
new java.net.URL("https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-gradle-plugin-api/1.3.11/kotlin-gradle-plugin-api-1.3.11.pom").openStream()
If you received a connection timeout, it confirms this theory. In this case you need to buy and have proxy/vpn connected in order to be able to download these dependencies.
Check your gradle and kotlin (or Java) versions.
I got the same error and my issue is solved by specifying the kotlin version in build.gradle:
Before:
plugins {
id 'org.jetbrains.kotlin.jvm'
}
After:
plugins {
id 'org.jetbrains.kotlin.jvm' version "1.4.10"
}
In my case (Ubuntu 20.04), problem was with gradle 7.2, installed from snap.
I have removed gradle 7.2, installed from snap and install gradle 7.2 from sdkman. Works fine for me.
If you are using java like me .I got the issue fixed by adding the following:
Root gradle
dependencies {
ext.kotlin_version = '1.4.10'
classpath "com.android.tools.build:gradle:7.0.4"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.38.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
......
}
App gradle file
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}
dependencies {
implementation "com.google.dagger:hilt-android:2.38.1"
kapt "com.google.dagger:hilt-compiler:2.38.1"
......
}
Ok, so the answer was very simple all along. For some reason I activated gradle's "Offline work" toggle and that was the cause of the problem.
To disable it simply go to Settings > Build, Execution, Deployment > Build Tools > Gradle and deselect the "Offline work" checkbox.
In my case the problem was because Charles Proxy. After closing Charles I could start working again
I updated my Kotlin version to 1.7.20 and fixed this problem.
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
I recently had similar issue with an empty project autogenerated by Intellij Idea.
Solved this problem by combining Java and Gradle versions.
Initially I had Oracle Java 8 with Gradle 6.8.3.
After several attempts I found a working combination - AdoptOpenJDK 11 and Gradle 5.6.4
In my case I changes the Gradle JVM in Settings > Build, Execution, Deployment > Build Tools > Gradle and it worked.
Disconnect from your VPN (or make sure you have an open internet connection), then restart Android Studio.
If you don't restart it sometimes it continues with invalid proxy properties.
This for Ktor devs. If you are working on a ktor application with the web project generator there is a chance the generator sets invalid jvm plugin version. So make sure you are setting correct version for jvm plugin. You can find the latest jvm plugin version here. Here is the sample build.gradle.kts file.
//Plugin section
plugins {
kotlin("jvm") version "1.8.0"
id("io.ktor.plugin") version "2.2.2"
}
//Dependancy section
dependencies {
...
testImplementation("io.ktor:ktor-server-tests-jvm:1.8.0")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:1.8.0")
...
}

gradle build fails cannot find sonar plugin "sonar-runner"

My gradle project cannot build. It fails with Plugin with id 'sonar-runner' not found.
Here's my build.gradle
subprojects {
apply plugin: 'sonar-runner'
}
I've refreshed my Gradle project. Then I've deleted my ~/.gradle/caches folder, but didn't work. Then I deleted my entire ~/.gradle folder, still the same error.
Any ideas please?
It's funny that gradle build doesn't run and gives me that exception, but bash gradle build runs fine, can someone clarify the difference in between? Thanks. My setup is on Mac OSX 10.11.6.
From https://docs.sonarqube.org/display/SONARQUBE51/Analyzing+with+Gradle:
Users of Gradle Sonar or Sonar Runner Plugins ? The existing Gradle
Sonar Runner and Gradle Sonar plugins, which are part of the Gradle
distribution, should no longer be used (See this official note from
the Gradleware team). The use of the Gradle SonarQube plugin is
recommended instead.
You have to use it as described at https://plugins.gradle.org/plugin/org.sonarqube
Build script snippet for use in all Gradle versions:
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.2.1"
}
}
apply plugin: "org.sonarqube"
Build script snippet for new, incubating, plugin mechanism introduced in Gradle 2.1:
plugins {
id "org.sonarqube" version "2.2.1"
}
Issue discussing this problem:
https://discuss.gradle.org/t/plugin-with-id-org-sonarqube-not-found/11588/10

Gradle dependency resolution error, <exclude org: module="l:ame="*" type="*

When running the "war" task for a web application project using Gradle 1.10, the following error started showing up when I included a dependency on cxf-bundle 2.6.13:
Could not resolve all dependencies for configuration ':runtime'.
Could not resolve <exclude org: module="l:ame="*" type="*.
Required by:
:gradle_dep_issue_example:unspecified > org.apache.cxf:cxf-bundle:2.6.13
java.lang.IllegalArgumentException (no error message)
Stopping and starting the gradle daemon has no effect, nor does clearing out the .gradle folder. However, running the war task and passing the --refresh-dependencies option does resolve the issue. Unfortunately, the --refresh-dependencies option must be used every time.
Here is a small build.gradle file which will reproduce the issue when the "downloadRuntimeDeps" task is run.
apply plugin: 'war'
repositories {
mavenCentral()
}
dependencies {
compile 'org.apache.cxf:cxf-bundle:2.6.13'
}
task downloadRuntimeDeps(type: Copy){
from configurations.runtime
into new File(getBuildDir(), "/runtime-deps/")
}
The issue ended up only impacting gradle version 1.10. I tested with versions 1.8 and 1.11, and neither had this problem.
There are no bug fixes included in the release notes for gradle 1.11 that reference an issue like this, so I assume this was fixed while resolving a seemingly unrelated issue.
The solution was to upgrade all my projects to use gradle 1.11

Debug Gradle plugins with IntelliJ

Problem
I want to use the interactive debugger with IntelliJ. Unfortunately, I can't convince IntelliJ to load and compile the plugin. However, I can do gradle clean build and the plugin builds and runs its tests as expected.
Specifically, I'm trying to debug local changes to gradle-js-plugin and IntelliJ says it can't find com.google.javascript.jscomp.CompilerOptions as well as spock.lang.Specification. (I'm thinking maybe it's something about the way they are loaded, but that's a guess.)
Things I've tried
NOTE: I didn't revert any processes between steps.
0. My First Guess
I noticed a howto on docs.codehaus.org. IntelliJ couldn't find org.gradle.launcher.GradleMain, so I've adapted it to use GradleLauncher with the following:
import org.gradle.GradleLauncher
class GradleScriptRunner {
public static void main(String[] args) {
GradleLauncher.newInstance(
"-p",
"/path/to/gradle-js-plugin/src/test/resources/build.gradle",
"clean assemble"
)
}
}
Per GradleLauncher's documentation.
Outcome: IntelliJ won't compile the project.
1. Per Peter Niederwieser's answer Fix idea project & debug via plugin
Steps
~# cd /path/to/gradle-js-plugin && gradle cleanIdea idea
Opened the newly created project and attempted to debug using the ScriptRunner from step 0.
Outcome: Project compiles (yay!), but I can only hit breakpoints in GradleScriptRunner.groovy.
2. Per Peter Niederwieser's answer run gradle CLI w/ special options
1 & 2. Merged for clarity:
~# export GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"
~# gradle clean assemble
Listening for transport dt_socket at address: 5005
Configure IntelliJ to connect to this port and start debugging (see image):
For this step I tried the following .gradle file configurations:
1. Use only build.gradle
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile findProject "/path/to/gradle-js-plugin"
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 13
* What went wrong:
A problem occurred evaluating root project 'resources'.
> No such property: findProject for class: org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 8 mins 50.498 secs
2. Use both build.gradle and settings.gradle
--settings.gradle--
include "/path/to/gradle-js-plugin"
--build.gradle--
apply plugin: 'groovy'
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'js'
buildscript {
repositories {
mavenLocal()
mavenCentral()
}
}
repositories {
mavenLocal()
mavenCentral()
}
Outcome:
FAILURE: Build failed with an exception.
* Where:
Build file '/path/to/gradle-js-plugin/src/test/resources/build.gradle' line: 5
* What went wrong:
A problem occurred evaluating root project 'resources'.
> Plugin with id 'js' not found.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 13.553 secs
My Setup
Gradle
~# gradle -v
------------------------------------------------------------
Gradle 1.0
------------------------------------------------------------
Gradle build time: Tuesday, June 12, 2012 12:56:21 AM UTC
Groovy: 1.8.6
Ant: Apache Ant(TM) version 1.8.2 compiled on December 20 2010
Ivy: 2.2.0
JVM: 1.7.0_04 (Oracle Corporation 23.0-b21)
OS: Linux 3.2.0-2-amd64 amd64
Java
~# java -version
java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
IntelliJ
IntelliJ IDEA Ultimate 117.499 w/ Bundled Gradle plugin
Hoping for
Any tips that'll get me into debug mode within the plugin.
I was able to debug gradle sources (including plugins) using -Dorg.gradle.debug=true (found on gradle forum):
Stop daemons if any:
./gradlew --stop
Run
./gradlew <task> --no-daemon -Dorg.gradle.debug=true
Connect remotely to gradle process (port 5005) - if using IntelliJ IDEA, see OP's image above
It should stop on breakpoints now.
BTW, I have created a separate IntelliJ IDEA project for gradle sources. Since I use gradle wrapper, I have grabbed the sources from
~/.gradle/wrapper/dists/gradle-1.11-all/7qd8qq8te5j4f5q9aaei3gh3lj/gradle-1.11/src
In IDEA I did File->Import Project, then selected the above path, then - "Create project from existing sources". Hit Next couple of times (made sure I didn't include any jars from lib/plugins directory, since IDEA would complain that most project files already exist).
I then created a remote debug configuration in that IDEA project and used it for debugging gradle.
First, it sounds like there is a problem with your IDEA Gradle project. If you run gradlew cleanIdea idea and then open the generated project from IDEA (rather than using the JetGradle plugin), all should be fine.
Second, if you still can't get the GradleMain/GradleLauncher (the former class does exist) approach to work, another approach is to debug the Gradle build as an external application. For that you need to add -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 to the GRADLE_OPTS environment variable, run the build from the command line, wait until it suspends, and then start a "Remote" run configuration (with corresponding settings) from IDEA. At that point the debugger should connect to the Gradle process and you should be up and running.
IntelliJ IDEA 12.1 provides ability to debug gradle tasks out of the box - right-click target task at the JetGradle tool window tasks list and choose 'debug'

Resources