# Set pluginManagement.repositories in init.gradle

**URL:** <https://discuss.gradle.org/t/set-pluginmanagement-repositories-in-init-gradle/40955>\
**Category:** Help/Discuss\
**Created:** [September 9, 2021, 8:18am UTC](https://discuss.gradle.org/t/set-pluginmanagement-repositories-in-init-gradle/40955 "2021-09-09T08:18:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EugenMayer](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eugenmayer/32/7673_2.png) [@EugenMayer](https://discuss.gradle.org/u/EugenMayer)\
**Post date:** [September 9, 2021, 8:18am UTC](https://discuss.gradle.org/t/set-pluginmanagement-repositories-in-init-gradle/40955/1 "2021-09-09T08:18:49Z")

</div>

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

```gradle
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

```gradle
* 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](https://discuss.gradle.org/t/access-providers-in-enterpriserepositoryplugin-in-init-gradle/40954) altogether

---

<div class="post-metadata">

**Author:** ![geissld](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/geissld/32/12115_2.png) [@geissld](https://discuss.gradle.org/u/geissld)\
**Post date:** [September 9, 2021, 8:50am UTC](https://discuss.gradle.org/t/set-pluginmanagement-repositories-in-init-gradle/40955/2 "2021-09-09T08:50:11Z")

</div>

Update:  
Had a closer look at the documentation:  
[https://docs.gradle.org/current/userguide/declaring\_repositories.html](https://docs.gradle.org/current/userguide/declaring_repositories.html)  
[https://docs.gradle.org/current/javadoc/org/gradle/api/credentials/PasswordCredentials.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.

```gradle
                      credentials(PasswordCredentials) {
                          username = settings.ext.ourNexusAnyUser
                          password = settings.ext.ourNexusAnyPassword
                      }

```

---

<div class="post-metadata">

**Author:** ![EugenMayer](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/eugenmayer/32/7673_2.png) [@EugenMayer](https://discuss.gradle.org/u/EugenMayer)\
**Post date:** [September 9, 2021, 9:21am UTC](https://discuss.gradle.org/t/set-pluginmanagement-repositories-in-init-gradle/40955/3 "2021-09-09T09:21:37Z")

</div>

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!
