MavenArtifactRepository

API Documentation:MavenArtifactRepository

An artifact repository which uses a Maven format to store artifacts and meta-data.

Repositories of this type are created by the RepositoryHandler.maven(org.gradle.api.Action) group of methods.

Properties

PropertyDescription
allowInsecureProtocol

Specifies whether it is acceptable to communicate with a repository over an insecure HTTP connection.

artifactUrls

The additional URLs to use to find artifact files. Note that these URLs are not used to find POM files.

authentication

The authentication schemes for this repository.

credentials

The credentials of the specified type used to authenticate with this repository.

name

The name for this repository. A name must be unique amongst a repository set. A default name is provided for the repository if none is provided.

url

The base URL of this repository. This URL is used to find both POMs and artifact files. You can add additional URLs to use to look for artifact files, such as jars, using MavenArtifactRepository.setArtifactUrls(java.lang.Iterable).

Methods

MethodDescription
artifactUrls(urls)

Adds some additional URLs to use to find artifact files. Note that these URLs are not used to find POM files.

authentication(action)

Configures the authentication schemes for this repository.

credentials(credentialsType)

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

credentials(credentialsType, action)

Configures the credentials for this repository using the supplied action.

credentials(action)

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

metadataSources(configureAction)

Configures the metadata sources for this repository. This method will replace any previously configured sources of metadata.

Script blocks

No script blocks

Property details

boolean allowInsecureProtocol

Specifies whether it is acceptable to communicate with a repository over an insecure HTTP connection.

For security purposes this intentionally requires a user to opt-in to using insecure protocols on case by case basis.

Gradle intentionally does not offer a global system/gradle property that allows a universal disable of this check.

Allowing communication over insecure protocols allows for a man-in-the-middle to impersonate the intended server, and gives an attacker the ability to serve malicious executable code onto the system.

See also: Want to take over the Java ecosystem? All you need is a MITM!

Set<URI> artifactUrls

The additional URLs to use to find artifact files. Note that these URLs are not used to find POM files.

AuthenticationContainer authentication (read-only)

The authentication schemes for this repository.

T credentials (read-only)

The credentials of the specified type used to authenticate with this repository.

If no credentials have been assigned to this repository, an empty set of credentials of the specified type is assigned to this repository and returned.

String name

The name for this repository. A name must be unique amongst a repository set. A default name is provided for the repository if none is provided.

The name is used in logging output and error reporting to point to information related to this repository.

URI url

The base URL of this repository. This URL is used to find both POMs and artifact files. You can add additional URLs to use to look for artifact files, such as jars, using MavenArtifactRepository.setArtifactUrls(java.lang.Iterable).

Method details

void artifactUrls(Object... urls)

Adds some additional URLs to use to find artifact files. Note that these URLs are not used to find POM files.

The provided values are evaluated as per Project.uri(java.lang.Object). This means, for example, you can pass in a File object, or a relative path to be evaluated relative to the project directory.

void authentication(Action<? super AuthenticationContainer> action)

Configures the authentication schemes for this repository.

This method executes the given action against the AuthenticationContainer for this project. The AuthenticationContainer is passed to the closure as the closure's delegate.

If no authentication schemes have been assigned to this repository, a default set of authentication schemes are used based on the repository's transport scheme.

repositories {
    maven {
        url "${url}"
        authentication {
            basic(BasicAuthentication)
        }
    }
}

Supported authentication scheme types extend Authentication.

void credentials(Class<? extends Credentials> credentialsType)

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 "${url}"
        credentials(PasswordCredentials)
    }
}

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

void credentials(Class<T> credentialsType, Action<? super T> action)

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 "${url}"
        credentials(AwsCredentials) {
            accessKey "myAccessKey"
            secretKey "mySecret"
        }
    }
}

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

void credentials(Action<? super PasswordCredentials> action)

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 "${url}"
        credentials {
            username = 'joe'
            password = 'secret'
        }
    }
}

void metadataSources(Action<? super MetadataSources> configureAction)

Configures the metadata sources for this repository. This method will replace any previously configured sources of metadata.