【问题标题】:Using a gradle plugin in a project where its dependency also use the same plugin在其依赖项也使用相同插件的项目中使用 gradle 插件
【发布时间】:2015-04-28 18:07:47
【问题描述】:

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

所以当我构建时我得到一个异常:

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 plugin: 'com.bmuschko.nexus' 添加到脚本的主体以使用插件我得到另一个异常:

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

我该如何解决这个问题?

settings.gradle

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

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

编辑:复制只需克隆 repo https://github.com/KIC/stackoverflow/tree/master/gradleproblem 并在 bar 目录中尝试 gradle tasks

EDIT2:似乎我可以通过省略插件并按照这个答案https://stackoverflow.com/a/16766946/1298461来解决nexus上传问题@

但是由于我还有一个 antlr 项目和第二个 antlr 项目扩展了第一个项目的语法,所以我在使用另一个插件时也遇到了同样的问题。我想当我使用父 build.gradle 和 subprojects{} 时我可以解决这个问题。但这正是我离开 maven 并转向 gradle 的原因。我的子模块可以也应该独立于不同的版本。

【问题讨论】:

  • 看来,如果插件已经应用,你可以直接使用它。无需重新应用它,只需通过配置并运行适当的任务。 gradle tasks 运行时是否列出了来自上述插件的任务?
  • 很遗憾,没有,由于该项目处于依赖关系中,因此设置将无法正常工作,因此 gradle 失败Could not find method nexus() for arguments
  • 该项目是否在线托管?
  • @Opal 不,它不在线

标签: java gradle


【解决方案1】:

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

我做了以下事情:

编辑 build.gradle(配置项目)

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

编辑 build.gradle(栏项目)

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 tasks,一切正常。

【讨论】:

  • 能否提供repos.gradle文件的相关内容?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-02-17
  • 1970-01-01
  • 1970-01-01
  • 2020-10-10
  • 1970-01-01
  • 1970-01-01
  • 2020-09-14
相关资源
最近更新 更多