API 文档 | MavenArtifactRepository |
---|
一个使用 Maven 格式存储 artifact 和元数据的 artifact 仓库。
此类仓库由 RepositoryHandler.maven(org.gradle.api.Action)
方法组创建。
属性 | 描述 |
allowInsecureProtocol | 指定是否允许通过不安全的 HTTP 连接与仓库通信。 |
artifactUrls | 用于查找 artifact 文件的额外 URL。请注意,这些 URL 不用于查找 POM 文件。 |
authentication | 此仓库的认证方案。 |
credentials | 用于使用指定类型凭据在此仓库进行身份验证的凭据。 |
name | 此仓库的名称。名称在仓库集合中必须是唯一的。如果未提供名称,将为仓库提供一个默认名称。 |
url | 此仓库的基础 URL。此 URL 用于查找 POM 和 artifact 文件。您可以使用 |
方法 | 描述 |
artifactUrls(urls) | 添加用于查找 artifact 文件的额外 URL。请注意,这些 URL 不用于查找 POM 文件。 |
authentication(action) | 配置此仓库的认证方案。 |
credentials(credentialsType) | 配置此仓库的凭据,这些凭据将由构建提供。 |
credentials(credentialsType, action) | 使用提供的 action 配置此仓库的凭据。 |
credentials(action) | 使用提供的 action 配置此仓库的用户名和密码凭据。 |
metadataSources(configureAction) | 配置此仓库的元数据源。此方法将替换之前配置的任何元数据源。 |
指定是否允许通过不安全的 HTTP 连接与仓库通信。
出于安全目的,这有意要求用户逐案选择使用不安全的协议。
Gradle 有意不提供允许全局禁用此检查的系统/gradle 属性。
允许通过不安全的协议进行通信,可能导致中间人冒充目标服务器,并使攻击者能够在系统上 提供恶意可执行代码。
AuthenticationContainer
authentication
(只读)
此仓库的认证方案。
URI
url
此仓库的基础 URL。此 URL 用于查找 POM 和 artifact 文件。您可以使用 MavenArtifactRepository.setArtifactUrls(java.lang.Iterable)
方法添加额外的 URL 来查找 artifact 文件,例如 jar。
void
artifactUrls
(Object
...
urls)
Object
...添加用于查找 artifact 文件的额外 URL。请注意,这些 URL 不用于查找 POM 文件。
提供的值会根据 Project.uri(java.lang.Object)
进行评估。这意味着,例如,您可以传入一个 File
对象,或者相对于项目目录的相对路径进行评估。
void
authentication
(Action
<? super AuthenticationContainer
>
action)
Action
<? super AuthenticationContainer
>配置此仓库的认证方案。
此方法对本项目的 AuthenticationContainer
执行给定的 action。此 AuthenticationContainer
作为 closure 的委托传递给 closure。
如果尚未为此仓库分配认证方案,则将根据仓库的传输方案使用一组默认的认证方案。
repositories {
maven {
url = "https://example.com/m2"
authentication {
basic(BasicAuthentication)
}
}
}
支持的认证方案类型扩展自 Authentication
。
void
credentials
(Class
<? extends Credentials
>
credentialsType)
Class
<? extends Credentials
>配置此仓库的凭据,这些凭据将由构建提供。
凭据将根据仓库名称从 Gradle 属性提供。如果无法解析此仓库的凭据,并且该仓库将在当前构建中使用,则构建将无法启动并指向缺失的配置。
repositories {
maven {
url = "https://example.com/m2"
credentials(PasswordCredentials)
}
}
目前支持以下凭据类型作为 credentialsType
参数:
使用提供的 action 配置此仓库的凭据。
如果尚未为此仓库分配凭据,则会将指定类型的空凭据集分配给此仓库,并将其提供给配置 action。如果此仓库已指定凭据,则会将其传递给给定的配置 action。
repositories { maven { url = "https://example.com/aws/proxy" credentials(AwsCredentials) { accessKey = "myAccessKey" secretKey = "mySecret" } } }
目前支持以下凭据类型作为 credentialsType
参数:
void
credentials
(Action
<? super PasswordCredentials
>
action)
Action
<? super PasswordCredentials
>使用提供的 action 配置此仓库的用户名和密码凭据。
如果尚未为此仓库分配凭据,则会将一组空的用户名和密码凭据分配给此仓库并传递给 action。
repositories { maven { url = "https://example.com/m2" credentials { username = 'joe' password = 'secret' } } }
void
metadataSources
(Action
<? super MetadataSources
>
configureAction)
Action
<? super MetadataSources
>配置此仓库的元数据源。此方法将替换之前配置的任何元数据源。