繁体   English   中英

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

[英]IntelliJ Kotlin multiplatform project Gradle sync very long

我为AndridiOS (移动共享库)创建了一个新的Kotlin Multiplatform项目。 该项目运行良好,但是每次我运行Gradle sync时, 每次都需要5分钟以上。 它总是卡在同一行上:

Gradle:为根项目“ MyProject”构建模型“ org.jetbrains.kotlin.gradle.KotlinMPPGradleModel”

为什么要花这么长时间?

我正在使用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
}

问题的屏幕截图:

在此处输入图片说明

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

如该问题所述,您可能可以尝试一种解决方法,该解决方法实际上是将{ content { excludeGroup("Kotlin/Native" } }repositories块中的每个项目。

正如@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")
            }
        }
    }

尝试使用--parallel选项从命令行运行Gradle任务。

否则,请参考本指南以介绍Gradle执行情况https://guides.gradle.org/performance/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM