解决后,无法更改配置':core:classpath'的依赖关系。 Gradle按需配置问题

时间:2019-07-24 15:01:53

标签: android gradle build.gradle

我有一个带有1个应用程序模块(MyApplication)和1个库模块(核心)的项目。 当我尝试查看“ gradlew MyApplication:dependencies”时, 我遇到了错误

* What went wrong: A problem occurred evaluating project ':core'.
> Cannot change dependencies of configuration ':core:classpath' after it has been resolved.

在顶层目录中,我使用以下命令build.gradle:

   ...
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
    }
}
   ...

我也设置

  

org.gradle.configureondemand = true

在MyApplication目录中,我具有带有典型应用程序配置的build.gradle

apply plugin: "com.android.application"
...

在核心目录中,我具有build.gradle:

...
buildscript {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
    }
}
...

请询问是否需要gradle文件中的其他信息。

很抱歉,该项目在源代码和整个gradle文件主体的公开方面受到限制。

1 个答案:

答案 0 :(得分:0)

最后,我了解出了什么问题。 在顶层文件夹build.gradle中,我们已经定义了与android构建工具相关的内容:

buildscript {
    repositories {
        google()
        maven {
            url 'https://maven.fabric.io/public'
        }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'io.fabric.tools:gradle:1.26.1'
    }
}

因此我们需要从应用程序或库模块中删除此定义:

apply plugin: "com.android.library"

apply plugin: "maven"
apply plugin: "maven-publish"

ext.getArtifactId = {
    return "core"
}

if(project.hasProperty("PATH_SET_VERSION") == true){
    apply from: project.property("PATH_SET_VERSION").toString()
}

repositories {
    maven {
        url 'https://maven.google.com/'
        name 'Google'
    }
    jcenter()
    mavenLocal()
    maven {
        url "our local repositiry"
    }
    maven {
        url "https://google.bintray.com/flexbox-layout"
    }
}

buildscript {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1' // it's not needed here, so better to delete this dependencies {...} section
    }
}