Resolving dependency configuration 'implementation' is not allowed as it is defined as 'canBeResolved=false'

I’m updating a below old project gradle files (5.5.1) to use gradle 8.5. Replaced ‘compile’ with ‘implementation’ and getting below error.

Resolving dependency configuration ‘implementation’ is not allowed as it is defined as ‘canBeResolved=false’.
Instead, a resolvable (‘canBeResolved=true’) dependency configuration that extends ‘implementation’ should be resolved.

I’m sure I’ve really messed up something. appreciate your help!

project/build.gradle

allprojects {
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'maven'

    repositories {
        mavenCentral()
    }

    configurations {
        provided
        compile.extendsFrom provided
    }

    dependencies {
        provided files('../../lib/spring-aop-5.3.20.jar')
        provided files('../../lib/spring-aspects-5.3.20.jar')
        ...
        testCompile 'junit:junit:4.12'
    }
}

project/common/build.gradle

dependencies {
    compile files('../../lib/commons-dbcp-1.4.jar')
    compile files('../../lib/commons-pool-1.5.6.jar')
    compile files('../../lib/spring-aop-5.3.20.jar')
    compile files('../../lib/spring-aspects-5.3.20.jar')	
}

jar {
    baseName = 'common'
	mkdir "dist"	
    doLast {
        copy {
           from('build/libs')
            into('dist')
        }
    }
}

task cleanDir(type: Delete) {
    delete 'dist'
}

tasks.clean.doLast() {
    tasks.cleanDir.execute()
}

project/abcws/build.gradle

dependencies {
    compile project(':common')
}

jar {
    baseName = 'abcws'
    
    from((configurations.compile - configurations.provided).collect { it.isDirectory() ? it : zipTree(it) }) {
        exclude "META-INF/*.SF"
        exclude "META-INF/*.DSA"
        exclude "META-INF/*.RSA"
    }

    manifest {
        attributes 'Implementation-Title': 'Test',
                'Implementation-Version': version,
                'Built-By': System.getProperty('user.name'),
                'Built-Date': new Date(),
                'Built-JDK': System.getProperty('java.version'),
                'Class-Path': './'
    }
	
	mkdir "dist"	
    doLast {
        copy {
           from('build/libs')
            into('dist')
        }
    }
}

task cleanDir(type: Delete) {
    delete 'dist'
}

tasks.clean.doLast() {
    tasks.cleanDir.execute()
}

For a quick-fix, use the runtimeClasspath configuration where resolve the dependencies instead of implementation.

Generally, for a smoother upgrade experience, do not skip major versions.

  • upgrade to the latest patch release within the major version
  • fix all deprecation warnings
  • upgrade to the latest patch release in the directly following major version
  • rinse and repeat

Also, if you really want to use such a bad-practice fat jar, I’d recommend to at least use the shadow plugin of John R. Engelman, as it at least sails around some of the cliffs you will hit with them like excluding signature files.

But actually, you have many more bad practices there you should consider reworking. For example you should not use allprojects { ... } or similar cross-project configuration, if you really need to use local jar files as dependencies instead of proper dependencies that know their dependencies, at least use a flatDir repository and neither files(...) nor fileTree(...), you must not try to “call” a task explicitly, this execute() method was a big mistake and is long gone without replacement, don’t add that copying to the jar task, but make a separate task of type Sync (or Copy, but usually you want Sync) that does from(tasks.jar), …

And a personal recommendation, switch to Kotlin DSL. By now it is the default, you immediately get type-safe build scripts, actually helpful error messages if you mess up the syntax, and an amazingly better IDE support when using a good IDE like IntelliJ IDEA or Android Studio. :slight_smile: