# credentials

abstract fun credentials(action: Action<in PasswordCredentials>)

Configures the username and password credentials for this repository using the supplied action.

If no credentials have been assigned to this repository, an empty set of username and password credentials is assigned to this repository and passed to the action.

    repositories {
        maven {
            url = "https://example.com/m2"
            credentials {
                username = 'joe'
                password = 'secret'
            }
        }
    }

Content copied to clipboard

#### Throws

java.lang.IllegalStateException

when the credentials assigned to this repository are not of type PasswordCredentials

abstract fun <T : Credentials?> credentials(credentialsType: Class<T>, action: Action<in T>)

Configures the credentials for this repository using the supplied action.

If no credentials have been assigned to this repository, an empty set of credentials of the specified type will be assigned to this repository and given to the configuration action. If credentials have already been specified for this repository, they will be passed to the given configuration action.

    repositories {
        maven {
            url = "https://example.com/aws/proxy"
            credentials(AwsCredentials) {
                accessKey = "myAccessKey"
                secretKey = "mySecret"
            }
        }
    }

Content copied to clipboard

The following credential types are currently supported for the `credentialsType` argument:

- org.gradle.api.artifacts.repositories.PasswordCredentials
- org.gradle.api.credentials.AwsCredentials

#### Throws

java.lang.IllegalArgumentException

if `credentialsType` is of a different type to the credentials previously specified for this repository

abstract fun credentials(credentialsType: Class<out Credentials>)

Configures the credentials for this repository that will be provided by the build.

Credentials will be provided from Gradle properties based on the repository name. If credentials for this repository can not be resolved and the repository will be used in the current build, then the build will fail to start and point to the missing configuration.

    repositories {
        maven {
            url = "https://example.com/m2"
            credentials(PasswordCredentials)
        }
    }

Content copied to clipboard

The following credential types are currently supported for the `credentialsType` argument:

- org.gradle.api.credentials.PasswordCredentials
- org.gradle.api.credentials.AwsCredentials
- org.gradle.api.credentials.HttpHeaderCredentials

#### Since

6.6

#### Throws

java.lang.IllegalArgumentException

if `credentialsType` is not of a supported type