Fail to download when using 'gradle init'

I am new to gradle and I wan to migrate one existing maven project to gradle.

I have writen the init.gradle file:

allprojects {
	repositories {
		maven {
			url = uri("URL1")
			credentials {
				username = System.getenv("REPO_USER")
				password = System.getenv("REPO_PASS")
			}
		}
		maven {
			url = uri("URL2")
			credentials {
				username = System.getenv("REPO_USER")
				password = System.getenv("REPO_PASS")
			}
			mavenContent {
				snapshotsOnly()
			}
		}
		maven {
			url =uri("URL3")
			credentials {
				username = System.getenv("REPO_USER")
				password = System.getenv("REPO_PASS")
			}
		}
	}
}

When I issue the ‘gradle init’ command it still tries to download from maven central (which is not accessible), as show the console error:

Execution failed for task ‘:init’ (registered by plugin ‘org.gradle.build-init’).

Could not resolve all files for configuration ‘detachedConfiguration1’.
Could not resolve org.apache.maven:maven-core:3.9.5.
Required by:
detached context for root project ‘horus-common-api’
Could not resolve org.apache.maven:maven-core:3.9.5.
Could not get resource ‘https://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.9.5/maven-core-3.9.5.pom’.
Could not GET ‘https://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.9.5/maven-core-3.9.5.pom’.

How can I use gradle init with a private repository ?

I use gradle version 9.6.1.

It seems there is no way to customize the repository used for gradle init Maven migration, but it uses hard-coded mavenCentral(): Provide an option for Gradle `init` Maven Migration to use a custom Maven repository · Issue #20596 · gradle/gradle · GitHub

You can maybe use some proxy to intercept those calls and redirect them to the internal repository, or maybe by configuring DNS resolution of the MC URL so that it lands on your internal system.

But actually the Maven migration is anyway quite limited, often it is anyway better to just write the build ground-up yourself. :man_shrugging:

There is also this PR that should had solved the issue, but unfortunately it was closed unmerged: Add custom Maven repository support for gradle init by reinsch82 · Pull Request #36902 · gradle/gradle · GitHub