Gradle:从另一个插件添加插件依赖 [英] Gradle: add plugin dependency from another plugin

查看:535
本文介绍了Gradle:从另一个插件添加插件依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建gradle自定义插件,我的任务之一是确保将另一个插件应用于同一项目.因为它将在它之上运行. 我想让我的插件用户避免对另一个插件建立显式依赖关系-我想在我的插件中进行操作.

所以,我想拥有这个插件( https://plugins.gradle.org /plugin/org.hidetake.ssh ).这是我的依赖.

创建插件的方式-我只是在groovy上创建一个类代码,将其放在buildSrc \ src \ main \ groovy中,然后在项目中应用groovy插件.因此,我的自定义插件在构建阶段可见.它可以正常工作,对于同一个项目,我很少有其他插件以这种方式完成,所以现在还可以.

我已经浏览了其他主题和Google,以查找相同的问题,但我无法为我完成这项工作.这就是我应用代码的方式:

void apply(Project project) {

    project.buildscript {
      repositories {
        maven {
          url "https://plugins.gradle.org/m2/"
        }
      }
      dependencies {
        classpath "org.hidetake:gradle-ssh-plugin:1.1.3"
      }
    }

    project.apply plugin: "org.hidetake.ssh"
    ...

我收到的错误消息:未找到ID为'org.hidetake.ssh'的插件. 我试图通过gradle api也使用project.repositories.mavenCentral()和project.dependencies.add和project.apply(plugin:'org.hidetake.ssh')来做到这一点-也不起作用-相同的错误消息.试图在project.dependencies.add("myConfig",[group:'org.hidetake',名称:'gradle-ssh-plugin',version:'1.1.3'])中使用长符号-没有结果.

欣赏是否有人可以指导正确的语法\使其工作.

解决方案

好,最后我明白了.要解决此问题,您需要执行以下操作:

  1. 将build.gradle放置在buildSrc目录中.
  2. 将插件的依赖项声明为 runtime .像这样:

    repositories {
        jcenter()
    }
    dependencies {
        runtime 'org.hidetake:gradle-ssh-plugin:2.6.0'
    }
    

  3. 在您自己的插件定义中显式应用插件.像这样:

    void apply(Project project) {
        project.pluginManager.apply('org.hidetake.ssh')
    ...
    

I'm creating gradle custom plugin and one of my tasks needs to be sure that another plugin applied to same project. Because it will operate on top of it. I want for users of my plugin to avoid setting up an explicit dependency to another plugin - I want to do it inside my plugin.

So, I want to have this plugin (https://plugins.gradle.org/plugin/org.hidetake.ssh) applied. It's my dependency.

The way how I create plugin - I just create a class code on groovy, put it in buildSrc\src\main\groovy and apply groovy plugin in project. So my custom plugin is visible to gradle on build phase. It works, I have few other plugins done this way for same project, so it's fine for now.

I've looked through other topics and google for same question, but I can not make this work for me. This how I apply the code:

void apply(Project project) {

    project.buildscript {
      repositories {
        maven {
          url "https://plugins.gradle.org/m2/"
        }
      }
      dependencies {
        classpath "org.hidetake:gradle-ssh-plugin:1.1.3"
      }
    }

    project.apply plugin: "org.hidetake.ssh"
    ...

The error message I got: Plugin with id 'org.hidetake.ssh' not found. I tried to do it via gradle api also using project.repositories.mavenCentral() and project.dependencies.add and project.apply(plugin:'org.hidetake.ssh') then - doesn't work also - same error message. Tried to use long notation in project.dependencies.add("myConfig",[group:'org.hidetake', name:'gradle-ssh-plugin', version:'1.1.3']) - no result.

Appreciate if someone can guide to the correct syntax\way to make it work.

解决方案

Ok, finally I got it. To solve the issue you need to do the following:

  1. Place build.gradle in your buildSrc directory.
  2. Declare dependency for the plugin as runtime. Like this:

    repositories {
        jcenter()
    }
    dependencies {
        runtime 'org.hidetake:gradle-ssh-plugin:2.6.0'
    }
    

  3. Apply plugin explicitly in your own plugin definition. Like this:

    void apply(Project project) {
        project.pluginManager.apply('org.hidetake.ssh')
    ...
    

这篇关于Gradle:从另一个插件添加插件依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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