-1

I'm building Kotlin simple Hello-Worl using Gradle

my build.gradle is:

/*
 * This build file was generated by the Gradle 'init' task.
 *
 * This generated file contains a commented-out sample Java project to get you started.
 * For more details take a look at the Java Quickstart chapter in the Gradle
 * user guide available at https://docs.gradle.org/4.3.1/userguide/tutorial_java_projects.html
 */

 // Apply the java plugin to add support for Kotlin

apply plugin: 'kotlin'


/*
plugins {
    id "org.jetbrains.kotlin.jvm" version "1.1.60"
}
*/

buildscript {
    ext.kotlin_version = '1.1.60'
// In this section you declare where to find the dependencies of your project
    repositories {
       mavenCentral()
      // jcenter()
    }
// In this section you declare the dependencies for your production and test code
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

sourceSets {
    main.kotlin.srcDirs += 'src/kotlin'
    main.resources.srcDirs += 'src/resources'
}

    dependencies {
        compile 'org.slf4j:slf4j-api:1.7.7'
        compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
        testCompile 'junit:junit:4.12'
    }

    kotlin {
        experimental {
            coroutines 'enable'
        }
    }

    compileKotlin {
        kotlinOptions.suppressWarnings = true
    }

    compileKotlin {
        kotlinOptions {
            suppressWarnings = true
        }
    }

and Main.kt is:

fun main(args: Array<String>) {
    println("kotlin!")
}

upon running Gradle buil, I got the below error:

enter image description here

Notes: - I'm new to gradle so built it as below 2 steps:

Step 1: enter image description here

Step 2: enter image description here

UPDATE

As per the first answer, I tried getting the files locally, I created another folder named lib and downloaded the *.jar files into it, so I got the gradle.build as below:

buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
        flatDir {
           dirs 'libs'
        }
    }
    dependencies {
        classpath fileTree(include: ['*.jar'], dir: 'libs')
        classpath files('kotlin-gradle-plugin-1.1.60.jar')
    }
}

apply plugin: 'kotlin'

sourceSets {
    main.kotlin.srcDirs += 'src/kotlin'
    main.resources.srcDirs += 'src/resources'
}

dependencies {
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile name: 'kotlin-stdlib-1.1.60'
    testCompile 'junit:junit:4.12'
}

kotlin {
    experimental {
        coroutines 'enable'
    }
}

compileKotlin {
    kotlinOptions.suppressWarnings = true
}

compileKotlin {
    kotlinOptions {
        suppressWarnings = true
    }
}

Below the revised structure and new error I got:

enter image description here

UPDATE

U copied all the required repositories .jar and .pom to folder:

C:\Users\.m2\repository\org\jetbrains\

I copied for example: ...\kotlin\kotlin-std\1.1.60\kotlin-stdlib-1.1.60.jar And ...\annotations\13.0\annotations-13.0.jar

And used

mavenLocal()

But still getting the same error :(

Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203

1 Answers1

2

I found the issue to be with our company proxy that prevented such thing, so I solved the issue by downloading the required repository in my hole laptop then copied them to the company one.

First, I created a separate folder, named it jars.

After that I downloaded the required file from here and saved it in the jars folder.

Then I installed it into the local repository using the command:

mvn install:install-file -Dfile=utility.jar -DgroupId=com.company -DartifactId=utility -Dversion=0.0.1 -Dpackaging=jar

Such as:

mvn install:install-file -Dfile=kotlin-stdlib-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-stdlib -Dversion=1.1.60 -Dpackaging=jar

Notes:

To do the above correctly, the maven is required to be downloaded from here and added to the path.

And command above is required to be run from the jars folder, that contains the downloaded repository:

enter image description here

Then I found that the repository had been downloaded into C:\Users\<user>\.m2\ folder:

enter image description here

After copying them into my office laptop, I called them from the mavenLocal():

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile ("org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version")
}

UPDATE

To download the full repository in one shoot instead of downloading the required files one by one, then the following command can be used:

mvn dependency:get -DrepoUrl=something -Dartifact=group:artifact:version

Such as:

mvn dependency:get -DrepoUrl=https://mvnrepository.com/artifact/org.jetbrains.kotlin -Dartifact=org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.60

For some reason 3 files failed to be downloaded, so I got them downloaded manually and installed as per the initial explanation,the files are:

org.jetbrains.kotlin:kotlin-android-extensions:jar:original:1.1.60 => here

org.jetbrains.kotlin:kotlin-compiler-runner:jar:original:1.1.60 => here

org.jetbrains.kotlin:kotlin-build-common:jar:tests:1.1.60 => here

and got them installed using the below commands:

mvn install:install-file -Dfile=kotlin-android-extensions-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-android-extensions -Dversion=1.1.60 -Dpackaging=jar

mvn install:install-file -Dfile=kotlin-compiler-runner-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-compiler-runner -Dversion=1.1.60 -Dpackaging=jar

mvn install:install-file -Dfile=kotlin-build-common-1.1.60.jar -DgroupId=org.jetbrains.kotlin -DartifactId=kotlin-build-common -Dversion=1.1.60 -Dpackaging=jar

Considering all the above done, the below build.gradle worked perfectly for me:

// set up the kotlin-gradle plugin
buildscript {
    ext.kotlin_version = '1.1.60'
    repositories {
       mavenLocal()    //    mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

// apply the kotlin-gradle plugin
apply plugin: "kotlin"

// add kotlin-stdlib dependencies.
repositories {
    mavenLocal()  //  mavenCentral()
}

dependencies {
    //dependencies from a remote repositor
    compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

  //local file, that are not coming from repository, let's say my own jar files
  compile files('libs/Display.jar')
  compile fileTree(dir: 'libs', include: '*.jar')
}

jar {
    manifest {
        //Define mainClassName as: '[your_namespace].[your_arctifact]Kt'
        attributes ('Main-Class': 'MainKt', "Implementation-Title": "Gradle",
                   "Implementation-Version": 1)
    }
    // NEW LINE HERE !!!
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}

sourceSets {
    main.kotlin.srcDirs += 'src/kotlin'
    main.resources.srcDirs += 'src/resources'
}

kotlin {
    experimental.coroutines 'enable'
}

compileKotlin {
    kotlinOptions.jvmTarget= 1.8  // optional, Minimum jvmTarget of 1.8 needed since Kotlin 1.1
    kotlinOptions.suppressWarnings = true
}

enter image description here

Hasan A Yousef
  • 22,789
  • 24
  • 132
  • 203