簡體   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