在项目中使用 gradle 插件,其依赖项也使用相同的插件

2024-01-09

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

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

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.

我该如何解决这个问题?

设置.gradle

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

构建.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 https://github.com/KIC/stackoverflow/tree/master/gradleproblem并尝试gradle tasks在 bar 目录中

EDIT2:似乎我可以通过省略插件并遵循此答案来解决 Nexus 上传问题https://stackoverflow.com/a/16766946/1298461 https://stackoverflow.com/a/16766946/1298461

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


“com.bmuschko.nexus”插件已启用config项目。这就是出现以下错误的原因:插件“com.bmuschko.nexus”已位于脚本类路径中。脚本类路径上的插件不能应用在plugins {} 块中。将“应用插件:'com.bmuschko.nexus'”添加到脚本正文以使用该插件。

我做了以下事情:

编辑build.gradle(配置项目)

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

编辑build.gradle(bar项目)

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一切都很好。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在项目中使用 gradle 插件,其依赖项也使用相同的插件 的相关文章

随机推荐