Gradel init not working

I am trying to convert a maven project to gradle using gradle init. We need to use our organization’s maven repo and cannot access the central maven repo at repo.maven.org directly.

However even after adding the following in init.gradle script, I get error that gradle is not able to resolve the dependencies.

allprojects {
    buildscript {
        repositories {
            mavenLocal()
            maven {
                url "my maven repo"
            }
            mavenCentral()
        }
    }

    repositories {
        mavenLocal()
        maven {
            url "my maven repo"
        }
        mavenCentral()
    }

    settingsEvaluated {
        pluginManagement {
            repositories {
                mavenLocal()
                maven {
                    url "my maven repo"
                }
                mavenCentral()
            }
        }
    }
}

and cannot access the central maven repo at repo.maven.org directly.

That’s what mavenCentral() is. If you do not want to look there directly, you need to remove those.

So what exactly can not be found? A plugin? A normal compile/runtime dependency? Not 100% sure it is related, but it is strange the way you define the plugin repos. Why do you delay that? Assuming it is plugins your build cannot resolve, this actually could be related. Plus, you do not even specify the standard plugin repo (gradlePluginPortal()).

Just move the pluginManagement {} block into your settings.gradle file and drop the settingsEvaluated {} part:

// in `settings.gradle`

pluginManagement {
    repositories {
        mavenLocal()
        maven {
            url ...
        }
        // unless you also do not want to directly access the standard plugin repo
        gradlePluginPortal()
    }
}

Ok I created a new file called settings.gradle in the ~/.gradle directory (same place where I have the init.gradle file) and dropped the pluginManagement section there. However I am still getting the same error. This is what the build is trying to resolve and fails.

> :init > Resolve dependencies of :detachedConfiguration1 > aether-connector-basic-1.1.0.pom
> :init > Resolve dependencies of :detachedConfiguration1 > aether-transport-wagon-1.1.0.pom
> :init > Resolve dependencies of :detachedConfiguration1 > wagon-provider-api-3.4.2.pom
> :init > Resolve dependencies of :detachedConfiguration1 > maven-core-3.6.3.pom
> :init > Resolve dependencies of :detachedConfiguration1 > maven-compat-3.6.3.pom
> :init > Resolve dependencies of :detachedConfiguration1 > wagon-http-3.4.2.pom

What creates these detached Configurations? Those are special and something would have created them explicitly

I dont think so. I get the same messages on my personal PC when I try to create a gradle project from a maven one. Only difference is my personal PC does not have a artifactory maven repo and resolves dependencies from the net directly.

No idea how that relates to what I asked.

I am going to assume you understand what a Gradle Configuration is and start from there. Various things create these Configurations - plugins, your build, etc.

There is a special kind of Configuration called detached - see ConfigurationContainer - Gradle DSL Version 7.4.2.

So I am asking who creates these.

I have no idea what creates this detachedconfiguration. I also tried to convert a simple spring boot project which I created from start.spring.io from maven to gradle using gradle init and I got the same detachedConfiguration messages.

My other question is even if that be the case, how can I force the reoslution of the artifacts in the detachedConfiguration to point to my organizations maven repo instead of trying to resolve it from Central Repository:

The gradle init plugin creates these detached configurations.

Also currently there seems to be no way to resolve them from a custom maven repo. And I cannot access the repo at repo.maven.org

As far as I know, you cannot influence that.

The plugin adding the init task is not only using a detached configuration, it also uses a detached resolver that is completely independent from what you write in any build script, settings script, or init script.

For this detached resolver it uses hard-coded mavenCentral() to resolve these dependencies it needs for getting the model out of your POM to create a Gradle build from it.

The only way would be outside of Gradle, using some Proxy or DNS trickery.

But it is probably easier to just create the Gradle build from scratch instead of using the init task for the conversion.