4
votes

I'm trying to set up a project building Kotlin code with Gradle. I've followed instructions here on how to set up the build.gradle file but am receiving an error

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.0'
    }
}

apply plugin: 'kotlin'

With this I get the error:

FAILURE: Build failed with an exception.

I've also tried the "newer" way of specifing the plugin

plugins {
    id "org.jetbrains.kotlin.jvm" version "1.2.0"
}

Which gives this error:

  • What went wrong: Plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.2.0'] 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.0') Searched in the following repositories: Gradle Central Plugin Repository

Version of Gradle

gradle -version

------------------------------------------------------------
Gradle 4.4

Kotlin (and openjdk) kotlin -version Kotlin version 1.2.0 (JRE 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)

Running on Ubuntu 17.10

I've never worked with Gradle before so not sure if I'm missing anything in the build file

2
Looks like this should work - are you sure your internet connection is working properly? The error indicates a problem with thisligi
Yes definitely connected to the internet and I am able to wget the repo.maven.appache.org link from the OPschizoid90

2 Answers

1
votes

Try this. It works:

buildscript {
    ext.kotlin_version = '1.2.10'

    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

apply plugin: 'kotlin'

repositories {
    mavenCentral()
}

dependencies {
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
1
votes

I never use the buildscript block. Try this instead:

plugins {
    id 'java'
    id 'org.jetbrains.kotlin.jvm' version '1.4.31'
}

repositories {
    mavenCentral()
    jcenter()
}


dependencies {
    implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.31'
}