Set pluginManagement.repositories in init.gradle

I try to set the pluginManagement.repositories in the init.gradle file similar to what I already do with
ext.RepoConfigurator for the usual dependency repositories.

Suddenly this no longer works in a matter that I have

apply plugin: EnterpriseRepositoryPlugin
class EnterpriseRepositoryPlugin implements Plugin<Gradle> {
    void apply(Gradle gradle) {
        gradle.settingsEvaluated { settings ->
            // code to determine and set settings.ext.ourNexusAnyUser / settings.ext.ourNexusAnyPassword
            settings.pluginManagement {
                repositories {
                  gradlePluginPortal()
                  
                  maven {
                      url = 'redacted'
                      credentials(PasswordCredentials) {
                          username settings.ext.ourNexusAnyUser
                          password settings.ext.ourNexusAnyPassword
                      }
                  }

                  maven {
                      name = 'kw-maven-releases'
                       url = 'redacted'
                      credentials(PasswordCredentials) {
                          username settings.ext.ourNexusAnyUser
                          password settings.ext.ourNexusAnyPassword
                      }
                  }
                } 
            }
        }
    }
}

with the error

* What went wrong:
Could not find method username() for arguments [provider(?)] on Credentials [username: null] of type org.gradle.internal.credentials.DefaultPasswordCredentials_Decorated.

I am unsure what actually changed overall. This issue came up with Access providers in EnterpriseRepositoryPlugin in init.gradle altogether

Update:
Had a closer look at the documentation:
https://docs.gradle.org/current/userguide/declaring_repositories.html
https://docs.gradle.org/current/javadoc/org/gradle/api/credentials/PasswordCredentials.html
the username is actually a property, so the problem is you have to use a assignment not a method call.

                      credentials(PasswordCredentials) {
                          username = settings.ext.ourNexusAnyUser
                          password = settings.ext.ourNexusAnyPassword
                      }
1 Like

I see, sorry. The odd thing i yet cannot wrap my head around is, why this actually worked and even works for the dependency repository configuration since years (why it still is wrong).

Either the compiler got pickier recently, but which one.

Anyway thank you a lot, it works like it should!