How can I create a Kotlin project that is being built using Gradle?

I am trying to create a new Kotlin project that builds using Gradle using IntelliJ IDEA (2016.2.5 on Ubuntu 16.04). When I do this, I immediately get an error message.

Here is what I am trying:

  • Select "Create New Project" on the welcome screen.

  • Select "Gradle" from the left pane, "Kotlin (Java)" to the right. Click "Next."

  • Enter "hello-world" as ArtifactId. Click "Next."

  • Make sure that "Create a separate module from the source set" and "Use the default shell Gradle" is selected, nothing more. Click "Next."

  • Use the default values ​​for the name and location of the project. Click Finish.

Then I immediately get this error:

Gradle 'hello-world' project refresh failed

Error: Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:1.1-M02-12.
       Searched in the following locations:
           https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1-M02-12/kotlin-gradle-plugin-1.1-M02-12.pom
           https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin/1.1-M02-12/kotlin-gradle-plugin-1.1-M02-12.jar
       Required by:
           :hello-world:unspecified

The generated one is build.gradleas follows:

version '1.0-SNAPSHOT'

buildscript {
    ext.kotlin_version = '1.1-M02-12'

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

How can I properly create a Kotlin project that builds with Gradle?

+4
source share
1 answer

In yours, build.gradlechange ext.kotlin_versionas follows:

 ext.kotlin_version = '1.1-M02'

It is a small mistake that the IDE plugin puts its own version in build scripts, not the Kotlin version.

And also add the 1.1 EAP repository to repositoriesboth in buildscriptand in the root area:

repositories {
    // ...
    maven { url "http://dl.bintray.com/kotlin/kotlin-eap-1.1" }
}

Kotlin artifacts related to EAP versions are not placed in Maven Central, as in public versions, and this repository is not automatically added to the generated build script.

Gradle, .

build.gradle .

+4

Source: https://habr.com/ru/post/1659666/


All Articles