【问题标题】:Gradle fail to download Kotlin repositoryGradle 无法下载 Kotlin 存储库
【发布时间】:2018-04-29 13:55:47
【问题描述】:

我正在使用Gradle 构建Kotlin 简单的Hello-Worl

我的build.gradle 是:

/*
 * 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
        }
    }

Main.kt 是:

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

在运行Gradle buil 时,出现以下错误:

注意事项: - 我是gradle 的新手,所以按照以下两个步骤构建它:

第 1 步:

第 2 步:

更新

根据第一个答案,我尝试在本地获取文件,我创建了另一个名为 lib 的文件夹并将 *.jar 文件下载到其中,所以我得到了 gradle.build 如下:

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

我得到了修改后的结构和新错误:

更新

U 将所有需要的存储库 .jar 和 .pom 复制到文件夹:

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

我复制了例如: ...\kotlin\kotlin-std\1.1.60\kotlin-stdlib-1.1.60.jar 和 ...\annotations\13.0\annotations-13.0.jar

用过

mavenLocal()

但仍然遇到同样的错误:(

【问题讨论】:

    标签: java maven gradle kotlin jcenter


    【解决方案1】:

    我发现问题出在我们公司的代理阻止了这种事情,所以我通过在我的笔记本电脑上下载所需的存储库然后将它们复制到公司的一个来解决这个问题。

    首先,我创建了一个单独的文件夹,将其命名为jars

    之后,我从here 下载了所需的文件并将其保存在jars 文件夹中。

    然后我使用以下命令将它安装到本地存储库中:

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

    如:

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

    注意事项:

    要正确执行上述操作,需要从here 下载maven 并添加到path

    上面的命令需要从包含下载的存储库的jars文件夹中运行:

    然后我发现仓库已经下载到C:\Users\&lt;user&gt;\.m2\文件夹:

    将它们复制到我的办公室笔记本电脑后,我通过mavenLocal() 给它们打电话:

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

    更新

    要一次下载完整的仓库,而不是一个个下载需要的文件,可以使用以下命令:

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

    如:

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

    由于某些原因3个文件下载失败,所以我手动下载并按照最初的说明安装,文件是:

    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

    并使用以下命令安装它们:

    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
    

    考虑到上述所有工作,以下build.gradle 对我来说非常适合:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-27
      • 1970-01-01
      • 2020-06-21
      • 1970-01-01
      • 2018-06-26
      • 2012-02-26
      相关资源
      最近更新 更多