gradle插件存储库如何更改? [英] How can the gradle plugin repository be changed?

查看:409
本文介绍了gradle插件存储库如何更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I work at a big company with a strict policy forbidding the unfiltered use of outside libraries. We have to pull everything from blessed corporate repositories, and not the bare internet, including gradle.org.

使用gradle最初的apply插件语法,以及buildscript块,我可以向我们的仓库中添加(祝福的)插件,并在构建中使用它们。换句话说:

Using gradle's original apply plugin syntax, in conjunction with a buildscript block, I can add (blessed) plugins to our repo and use them in builds. In other words:

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

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

apply plugin: "someplugin"

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

Instead, I want to be able to use the new plugins DSL, i.e.

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

(我意识到,私有存储网址

(I realize that the private repo url would need to be defined somewhere)

新的插件语法始终传到gradle.org,并且似乎没有提供替代下载网址的任何方式。有人知道一种方法吗?

The new plugin syntax always goes to gradle.org and does not appear to have any means to provide an alternate download url. Does anyone know of a way?

我已经仔细阅读了文档和互联网,却找不到答案。抱歉,如果答案是完全显而易见的。

I've scrutinized the documentation and the Internet and can't find the answer. Apologies if the answer is completely obvious.

非常感谢!

推荐答案

Gradle 3.5和(可能以后)



Gradle 3.5具有新的(孵化)功能,可以更好地控制插件依赖项解析,使用 pluginManagement DSL

Gradle 3.5 and (presumably) later

Gradle 3.5 has a new (incubating) feature, allowing finer control of the plugin dependency resolution, using the pluginManagement DSL:


插件解析规则允许您修改在
plugins {} 块中发出的插件请求,例如更改请求的版本或显式地指定实现工件坐标的

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.

要添加解析规则,请使用 resolutionStrategy {} pluginManagement {} 块中的c $ c>:

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

示例27.6。插件解析策略。

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'
      }
  }
}

这告诉Gradle使用指定的插件实现工件
,而不是使用其内置的从插件ID到
Maven / Ivy坐标的默认映射。

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.

pluginManagement {} 块只能出现在 settings.gradle
文件中,并且必须是文件中的第一个块。自定义Maven和Ivy
插件存储库中除了实际实现插件的
外,还必须包含插件标记工件。

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 中的存储库块与 pluginRepositories

The repositories block inside pluginManagement works the same as the pluginRepositories block from previous versions.

在Gradle 3.5之前,您必须定义<$ c $在您的 settings.gradle 中的c> pluginRepositories ,如sytolk的答案所述:

Prior to Gradle 3.5, you had to define the pluginRepositories block in your settings.gradle, as explained in sytolk's answer:


pluginRepositories {}块只能出现在settings.gradle
文件中,并且必须是文件中的第一个块。

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'
  }
}


这篇关于gradle插件存储库如何更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆