Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Cannot change dependencies of configuration ':core:classpath' after it has been resolved. Gradle configure on demand problem

Ask Question

I have a project with 1 app module (MyApplication) and 1 library module (core). When I'm trying to see 'gradlew MyApplication:dependencies', i'm having an error

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

In top-level directory I have build.gradle with this:

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

and also I set

org.gradle.configureondemand=true

In MyApplication directory I have build.gradle with typical application configuration

apply plugin: "com.android.application"

In core directory I have build.gradle with this:

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

Please ask if additional information from gradle files is needed.

I'm sorry it's project have limitations on disclosure of source code and whole gradle files body.

Finally I understood what's coming wrong. In top-folder build.gradle we already defined stuff related to android build tools:

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'

So we need to delete this definition from application or library modules:

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
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.