在项目的依赖项也使用相同插件的项目中使用gradle插件 [英] Using a gradle plugin in a project where its dependency also use the same plugin

查看:75
本文介绍了在项目的依赖项也使用相同插件的项目中使用gradle插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是gradle的新手(从maven离开).现在我有一个问题.我有一个gradle构建,我想在其中使用 com.bmuschko.nexus 插件.但是我的项目依赖于另一个我也想使用 com.bmuschko.nexus 插件的项目.

I am new to gradle (leaving from maven). Now I have a problem. I have a gradle build where I want to use the com.bmuschko.nexus plugin. But my project depends on another project where I also want to use the com.bmuschko.nexus plugin.

因此,在构建时会出现异常:

So when I build I get an Exception:

Plugin 'com.bmuschko.nexus' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add  "apply plugin: 'com.bmuschko.nexus'" to the body of the script to use the plugin.

但是,当我这样做时->将 apply插件:'com.bmuschko.nexus'添加到脚本主体以使用该插件,我会得到另一个异常:

But when I do so -> Add apply plugin: 'com.bmuschko.nexus' to the body of the script to use the plugin I get another exception:

> Failed to apply plugin [id 'com.bmuschko.nexus']
   > Plugin with id 'com.bmuschko.nexus' not found.

我该如何解决?

settings.gradle

settings.gradle

include ':config'
project(':config').projectDir = new File(settingsDir, '../zConfig')

build.gradle

build.gradle

plugins {
        // id "com.bmuschko.nexus" version "2.3" // already in classpath
        id "me.champeau.gradle.antlr4" version "0.1"
}

apply plugin: 'java'
apply plugin: 'maven'
//apply plugin: 'com.bmuschko.nexus'

dependencies {
        compile project(':config')
}

仅复制克隆仓库 https://github.com/KIC/stackoverflow/tree/master/gradleproblem 并尝试在bar目录中尝试 gradle任务

to reproduce just clone the repo https://github.com/KIC/stackoverflow/tree/master/gradleproblem and try gradle tasks in the bar directory

似乎我可以通过省略插件来解决链接上载问题,并按照以下答案进行操作 https://stackoverflow.com/a/16766946/1298461

Seems that I could solve the nexus upload problem by omitting the plugin and follow this answer https://stackoverflow.com/a/16766946/1298461

但是由于我还有一个antlr项目和第二个antlr项目,扩展了第一个语法,所以我对另一个插件也遇到了同样的问题.我认为当我使用父build.gradle和subprojects {}时,可以解决此问题.但这恰恰是我离开行家并走向胜利的原因.我的子模块可以并且也应该独立于不同版本使用.

But since I have also an antlr project and a second antlr project extending the grammar of the first, I have the very same problem just with another plugin. I think I could solve this when I use a parent build.gradle and subprojects{}. But this is exactly the reason why I leave maven and move to gradle. My sub-modules can and should also live independently with different versions.

推荐答案

'com.bmuschko.nexus'插件已经在 config 项目上.这就是以下错误的原因:插件'com.bmuschko.nexus'已经在脚本类路径中.脚本类路径上的插件不能在plugins {}块中应用.在脚本正文中添加"apply plugin:'com.bmuschko.nexus'"以使用该插件.

'com.bmuschko.nexus' plugin is already on config project. That's the reason of the following error: Plugin 'com.bmuschko.nexus' is already on the script classpath. Plugins on the script classpath cannot be applied in the plugins {} block. Add "apply plugin: 'com.bmuschko.nexus'" to the body of the script to use the plugin.

我做了以下事情:

编辑build.gradle(配置项目)

Edit build.gradle (config project)

apply plugin: 'java'
apply plugin: 'maven'
apply from: '../repos.gradle'

编辑build.gradle(栏项目)

Edit build.gradle (bar project)

buildscript {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.bmuschko:gradle-nexus-plugin:2.3'
    }
}

apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'com.bmuschko.nexus'
apply from: '../repos.gradle'

dependencies {
        compile project(':config')
}

然后我运行 gradle任务,一切正常.

Then I run gradle tasks and everything is ok.

这篇关于在项目的依赖项也使用相同插件的项目中使用gradle插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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