gradlegoogle-cloud-platformcataloggoogle-artifact-registrygoogle-cloud-artifact-repository

GCP Artifact Registry issue using artifactregistry protocol for importing Gradle version catalogs


I have a Maven repository in my GCP Artifact Registry. I am able to publish plugins and java artifacts to the repository using artifactrepository and the com.google.cloud.artifactregistry:artifactregistry-gradle-plugin:2.2.3 dependency. I am also able to import the plugins and other artifacts from the same repository in other projects.

However, when I try to import a version catalog using:

    versionCatalogs {
        libs {
            from("com.my.stuff:my-catalog:0.0.1")
        }
    }

I get the following error:

Could not resolve all dependencies for configuration 'incomingCatalogForLibs0'.

> Not a supported repository protocol 'artifactregistry': valid protocols are [file, http, https, gcs, s3, sftp]

My url is atrifactregistry://us-maven.pkg.dev/my-project

If I remove the version-catalog part, it works fine again. How am I supposed to import the version catalog along with my other plugins and artifacts?


Solution

  • I believe the issue occurs because Gradle’s version catalog does not support the artifactregistry:// protocol. The Gradle documentation specifies that version catalogs rely on DependencyHandler.create(), which only supports standard repository protocols like http, https, file, etc.

    So, use https:// Instead of artifactregistry://

    Update settings.gradle like this:

    dependencyResolutionManagement {
        repositories {
            maven {
                url = uri("https://us-maven.pkg.dev/project-name/my-repo")
                credentials {
                    username = "_json_key"
                    password = file("path/to/service-account-key.json").readText()
                }
            }
        }
        versionCatalogs {
            libs {
                from("com.my.stuff:my-catalog:0.0.1")
            }
        }
    }
    

    I hope this solution works!