IntelliJ Kotlin多平台项目Gradle同步时间很长

3
我已经创建了一个新的Kotlin Multiplatform项目,用于Andrid和iOS(移动共享库)。该项目正常运行,但每次运行Gradle同步时,都需要超过5分钟的时间。它总是卡在同一行上:
Gradle: Build model 'org.jetbrains.kotlin.gradle.KotlinMPPGradleModel' for root project 'MyProject'
为什么每次都要花这么长时间呢?
我正在使用Gradle 5.1版本。以下是我的build.gradle文件:
buildscript {
    ext.kotlin_version = '1.3.11'
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.8.1"
    }
}
plugins {
    id 'kotlin-multiplatform' version '1.3.11'
}
repositories {
    google()
    jcenter()
    mavenCentral()
    maven { url 'https://jitpack.io' }
}
repositories {
    mavenCentral()
}
group 'com.example'
version '0.0.1'

apply plugin: "com.android.library"
apply plugin: "com.jfrog.artifactory"
apply plugin: 'maven-publish'

android {
    compileSdkVersion 28
    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName version
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions.incremental = false
}

kotlin {
    targets {
        fromPreset(presets.android, 'android')
        // This preset is for iPhone emulator
        // Switch here to presets.iosArm64 to build library for iPhone device
        fromPreset(presets.iosX64, 'ios') {
            compilations.main.outputKinds('FRAMEWORK')
        }
    }
    sourceSets {
        commonMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib-common'
            }
        }
        commonTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test-common'
                implementation 'org.jetbrains.kotlin:kotlin-test-annotations-common'
            }
        }
        androidMain {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-stdlib'
            }
        }
        androidTest {
            dependencies {
                implementation 'org.jetbrains.kotlin:kotlin-test'
                implementation 'org.jetbrains.kotlin:kotlin-test-junit'
            }
        }
        iosMain {
        }
        iosTest {
        }
    }
}

configurations {
    compileClasspath
}

问题截图:

在此输入图片描述

3个回答

4

已知存在一个问题,即在每次同步时都会重新获取Kotlin/Native依赖项,这可能是您所看到的情况。您可以在此处查看详细信息并进行跟踪。

正如在该问题发布的内容中所述,有一个解决方法,您可以尝试在repositories块中的每个项目中添加{ content { excludeGroup("Kotlin/Native" } }


升级到最新版本(Kotlin 1.3.21 和 Gradle 5.2.1)解决了我的问题。 - checketts

1

正如@Brucelet所指出的那样,这是一个已知问题。为了补充他的回答,在Groovy中实现了完整的解决方法:

repositories {
    mavenCentral().content() {
        excludeGroup "Kotlin/Native"
    }
    google().content() {
        excludeGroup "Kotlin/Native"
    }
    jcenter() {
        content {
            excludeGroup("Kotlin/Native")
        }
    }
    maven { 
        url 'https://jitpack.io'
        content {
            excludeGroup("Kotlin/Native")
        }
    }
}

在 Kotlin DSL 中的代码如下:
repositories {
        mavenLocal().apply {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
        maven {
            url = uri("https://dl.bintray.com/soywiz/soywiz")
            content {
                includeGroup("com.soywiz")
                excludeGroup("Kotlin/Native")
            }
        }
        jcenter() {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
        google().apply {
            content {
                excludeGroup("Kotlin/Native")
            }
        }
    }

0

我已经尝试了指南中的所有方法。问题不在于构建,构建很快,只是同步出了问题。 - Sir Codesalot

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接