littlerobots / version-catalog-update-plugin

Gradle plugin for updating a project version catalog
Apache License 2.0
566 stars 23 forks source link

ModuleVersionNotFoundException: Cannot resolve external dependency x because no repositories are defined #152

Closed milahu closed 1 month ago

milahu commented 1 month ago

i want to add version-catalog-update-plugin to gradle2nix/build.gradle.kts

in #151, i have added this plugins block to build.gradle.kts

plugins {
  id("com.github.ben-manes.versions") version "0.41.0"
  id("nl.littlerobots.version-catalog-update") version "0.8.4"
}

ok, now gradlew versionCatalogUpdate fails to find org.apache.logging.log4j:log4j-core

org.gradle.internal.resolve.ModuleVersionNotFoundException: Cannot resolve external dependency org.apache.logging.log4j:log4j-core:{require 2.17.1; reject [2.0, 2.17.1)} because no repositories are defined.

$ ./gradlew versionCatalogUpdate --info
------------------------------------------------------------
: Project Dependency Updates (report to plain text file)
------------------------------------------------------------

Failed to determine the latest version for the following dependencies (use --info for details):
 - org.apache.logging.log4j:log4j-core
The exception that is the cause of unresolved state: org.gradle.internal.resolve.ModuleVersionNotFoundException: Cannot resolve external dependency org.apache.logging.log4j:log4j-core:{require 2.17.1; reject [2.0, 2.17.1)} because no repositories are defined.
Required by:
    project :

Gradle release-candidate updates:
 - Gradle: [8.8 -> 8.10.2]

require 2.17.1; reject [2.0, 2.17.1)

makes sense, because log4j was broken until 2.17.0

because no repositories are defined

makes no sense, because repos are declared in gradle2nix/settings.gradle.kts

dependencyResolutionManagement {
    repositories {
        mavenCentral()
        maven { url = uri("https://repo.gradle.org/gradle/libs-releases") }
    }
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}

ok, let me add repos to build.gradle.kts

allprojects {
    repositories {
        mavenCentral()
        maven { url = uri("https://repo.gradle.org/gradle/libs-releases") }
    }
}

ok, now gradlew versionCatalogUpdate fails with

Build was configured to prefer settings repositories over project repositories but repository 'MavenRepo' was added by build file 'build.gradle.kts'

ok, let me remove the dependencyResolutionManagement block from settings.gradle.kts

ok, now gradlew versionCatalogUpdate fails again with

The exception that is the cause of unresolved state: org.gradle.internal.resolve.ModuleVersionNotFoundException: Cannot resolve external dependency org.apache.logging.log4j:log4j-core:+ because no repositories are defined.


this makes no sense... is this a bug in version-catalog-update-plugin?

let me remove repos from settings.gradle.kts

says

You have 2 options from here; Remove central declaration to work with your current config For this you need to remove the `dependencyResolutionManagement` block from the `setting.gradle` file (=the new way). And then the `repositories` config in your `build.gradle` will work again (=the old way). Update to work the new way The way forward is to edit `build.gradle` removing that `repositories` declaration. And then edit `settings.gradle` to include the maven config.

currently repos are declared in gradle2nix/settings.gradle.kts ("the new way") so ideally version-catalog-update-plugin should "just work"

hvisser commented 1 month ago

I'd appreciate if you would provide a concise issue description with a example project that demonstrates the issue. From the wall of text above it appears your project is misconfigured and that the dependencies cannot be resolved because there's no valid repository definition.

milahu commented 1 month ago

example project that demonstrates the issue

gradle2nix

i have zero experience with gradle and im surprised that following gradle docs (and stackoverflow) does not solve my issue

the dependencies cannot be resolved because there's no valid repository definition

repos are declared in gradle2nix/settings.gradle.kts i tried to move the repos to gradle2nix/build.gradle.kts but no luck so the error "no repositories are defined" makes no sense

hvisser commented 1 month ago

If you have zero Gradle experience then first get the project working before filing issues here that are not related to the plugin. I'm unable to debug your Gradle setup.for you.

milahu commented 1 month ago

first get the project working

the project is "working" but adding version-catalog-update-plugin does not work

updating all dependencies of a project should be trivial for example, for npm projects there is ncu -u

hvisser closed this as completed

still an issue i dont see how my build.gradle.kts or settings.gradle.kts are wrong and the "no repositories are defined" error message is not helpful

... or do you think its funny to throw useless error messages so only "expert" gradle users know what to do?

hvisser commented 1 month ago

I understand your frustration, but as I'm trying to point out: this error is not thrown by this plugin.

If you'd have a clear example project for me to check out I'd take a look, but you only refer to an existing project that doesn't have your changes so I'm unable to do a quick check, and I do not have the bandwidth to figure out what you are doing to retrace your steps.