Home > Software engineering >  Why does adding a repository to build.gradle make it not find a dependency?
Why does adding a repository to build.gradle make it not find a dependency?

Time:09-17

I see that jCenter will be decomissioned in the distant future and one is asked to stop using it by Gradle warning. Therefore I have started the transition, and since I saw that simply replacing jcenter() with mavenCentral() resulted in missing dependencies, I opted to add the Maven Central before JCenter as a first start.

AFAIK, Gradle will visit the Maven repos in-order: google, then maven central, then jcenter. But what happens is that when I add it, Gradle is unable to find a dependency:

$ time ./gradlew build --stacktrace
FAILURE: Build failed with an exception.

* What went wrong:
Could not determine the dependencies of task ':app:compileReleaseKotlin'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find :unspecified:.
     Required by:
         project :app > project :cameramodule > id.zelory:compressor:2.1.0

...
Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
...
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find :unspecified:.
Required by:
    project :app > project :cameramodule > id.zelory:compressor:2.1.0


* Get more help at https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD FAILED in 15s

Diff

Date:   Thu Sep 9 01:46:58 2021  0200

    Prever Maven Central over JCenter repos

diff --git a/build.gradle b/build.gradle
index 6dd00f0..533e262 100644
--- a/build.gradle
    b/build.gradle
@@ -4,8  4,8 @@ buildscript {
     ext.kotlin_version = '1.3.72'
     repositories {
         google()
-        jcenter()
-
         mavenCentral()
         jcenter() // read-only as of March 2021
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:4.2.0'
@@ -25,8  25,8 @@ buildscript {
 allprojects {
     repositories {
         google()
-        jcenter()
-
         mavenCentral()
         jcenter() // read-only as of March 2021
     }
 }

CodePudding user response:

Checked out the .pom file of id.zelory:compressor:2.1.0 from maven central and found the following dependency:

<dependency>
    <groupId/>
        <artifactId>unspecified</artifactId>
    <version/>
</dependency>

.pom link: https://repo1.maven.org/maven2/id/zelory/compressor/2.1.0/compressor-2.1.0.pom

This dependency is that unresolved :unspecified: that fails your build.

Obviously this dependency means nothing and probably the publication script generates wrong pom.

You should implement the compression library and exclude the weird :unspecified: dependency:

implementation('id.zelory:compressor:2.1.0') {
    exclude module: 'unspecified'
}

EDIT: The compressor's GitHub project have an issue that suggest that the migration to maven central changed the .pom file: https://github.com/zetbaitsu/Compressor/issues/176

EDIT 2: Apparently it was fixed in version 2.1.1: https://github.com/zetbaitsu/Compressor/issues/179

  • Related