gradle - 如何更改 gradle 插件存储库?

我在一家大公司工作,该公司有严格的政策,禁止未经过滤地使用外部库。我们必须从受祝福的公司存储库中提取所有内容,而不是从裸露的互联网中提取所有内容,包括 gradle.org。

使用 gradle 的原始应用插件语法,结合 buildscript block ,我可以将(祝福的)插件添加到我们的 repo 并在构建中使用它们。换句话说:

buildscript {
    repositories {
        maven { url "https://privaterepo.myemployer.com" }
    }

    dependencies {
        // various dependencies
        classpath "org.something:some-plugin:1.0"
        ...
    }

apply plugin: "someplugin"

相反,我希望能够使用新的插件 DSL,即

plugins {
    id 'org.something.some-plugin' version '1.0'
}

(我意识到需要在某个地方定义私有(private) repo url)

新的插件语法总是转到 gradle.org 并且似乎没有任何方法可以提供备用下载 url。有人知道方法吗?

我仔细检查了文档和 Internet,但找不到答案。如果答案完全显而易见,我们深表歉意。

非常感谢!

最佳答案

Gradle 3.5 和(大概)更高版本

Gradle 3.5 有一个新的 (incubating) 功能,允许更好地控制插件依赖解析,using the pluginManagement DSL :

Plugin resolution rules allow you to modify plugin requests made in plugins {} blocks, e.g. changing the requested version or explicitly specifying the implementation artifact coordinates.

To add resolution rules, use the resolutionStrategy {} inside the pluginManagement {} block:

Example 27.6. Plugin resolution strategy.

settings.gradle
pluginManagement {
  resolutionStrategy {
      eachPlugin {
          if (requested.id.namespace == 'org.gradle.sample') {
              useModule('org.gradle.sample:sample-plugins:1.0.0')
          }
      }
  }
  repositories {
      maven {
        url 'maven-repo'
      }
      gradlePluginPortal()
      ivy {
        url 'ivy-repo'
      }
  }
}

This tells Gradle to use the specified plugin implementation artifact instead of using its built-in default mapping from plugin ID to Maven/Ivy coordinates.

The pluginManagement {} block may only appear in the settings.gradle file, and must be the first block in the file. Custom Maven and Ivy plugin repositories must contain plugin marker artifacts in addition to the artifacts which actually implement the plugin.

pluginManagement 中的 repositories block 与以前版本中的 pluginRepositories block 的工作方式相同。


Gradle 3.5 之前

在 Gradle 3.5 之前,您必须 define the pluginRepositories block在您的 settings.gradle 中,如 sytolk 的回答中所述:

The pluginRepositories {} block may only appear in the settings.gradle file, and must be the first block in the file.

pluginRepositories {
  maven {
    url 'maven-repo'
  }
  gradlePluginPortal()
  ivy {
    url 'ivy-repo'
  }
}

https://stackoverflow.com/questions/37285413/

相关文章:

c++ - #error 请为 _AFXDLL 构建使用/MD 开关

java - 错误 :Could not initialize class com. android

command-line - 如何从命令行构建 IntelliJ 项目?

c# - 如何获得本地 Visual Studio 构建完成的通知?

build - Gradle 全局构建目录

tfs - Cruise Control .Net 与 Team Foundation 构建

gcc - g++ 输出 : file not recognized: File format no

c# - NuGet 以代码 -1 退出 - 结果构建失败

xcode - 了解 Xcode 的 Copy Headers 阶段

gcc - 使用不同的 gcc 版本构建 boost