28
votes

I have a fresh install of IntelliJ, I created a new kotlin gradle project using the following settings:

Project 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
8
Please check that "Offline" option is not enabled in "Settings | Build... | Build Tools | Gradle"y.bedrov
@y.bedrov, it is not enabled.Morgoth
Did you manage to solve this? Considering just using a build.gradle insteadJosh Laird
I have the same issue with build.gradle, so I don't think it's related to the Kotlin DSL build script (on macos).Victor Grigoriu
I have the same problem with both using build.gradle or Kotlin DSL as well. Different PC, same internet connection it works. Tried to invalidate IntelliJ cache to no avail.MMauro

8 Answers

7
votes

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.

4
votes

(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.

4
votes
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"
//}
  1. gradle sync by commenting the above lines. The gradle will be set up.
  2. once the gradle is downloaded, uncomment those line and sync again.
  3. if the dependencies are not downloaded properly, run 'gradle build' in the terminal and click on gradle sync.

This solved the issue for me.

2
votes

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.

0
votes

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

0
votes

In my case the problem was because Charles Proxy. After closing Charles I could start working again

0
votes

In my case I changes the Gradle JVM in Settings > Build, Execution, Deployment > Build Tools > Gradle and it worked.

0
votes

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