【问题标题】:How do I preconfigure Gradle Plugin Repository?如何预配置 Gradle 插件存储库?
【发布时间】:2016-11-03 08:20:33
【问题描述】:

我想在 Gradle 中使用新奇特的 plugin { id: ''} 语法和存储在公司 Artifacotry 中的自定义内部插件。为此,我可以在settings.gradle only 中为 Gradle Plugin Repostiory 设置 maven 存储库。

我想在我的自定义 Gradle 包中全局设置它,该包将使用 Gradle 包装器下载。我可以在 $GRADLE/init.d/repositories.gradle 脚本中定义全局依赖库和 buildscript 依赖库,但是对于 Gradle 插件注册表我不能这样做,因为它需要放在 settings.gradle 中。

我怎样才能做到这一点?

【问题讨论】:

  • 你有没有办法做到这一点?

标签: gradle gradle-plugin


【解决方案1】:

您可以使用 Gradle API 中的 settingsEvaluated 方法完成此操作。

将以下内容放入初始化脚本中。

def ENTERPRISE_REPOSITORY_URL = "https://repo.gradle.org/gradle/repo"

settingsEvaluated { setting ->
    setting.pluginManagement.repositories {
        // Remove all repositories not pointing to the enterprise repository url
        all { ArtifactRepository repo ->
            if (!(repo instanceof MavenArtifactRepository) ||
                repo.url.toString() != ENTERPRISE_REPOSITORY_URL) {
                project.logger.lifecycle "Repository ${repo.url} removed. Only 
                        $ENTERPRISE_REPOSITORY_URL is allowed"
                remove repo
            }
        }

        // add the enterprise repository
        maven {
            name "STANDARD_ENTERPRISE_REPO"
            url ENTERPRISE_REPOSITORY_URL
        }
    }
}

【讨论】:

    猜你喜欢
    • 2016-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多