简体   繁体   English

Gradle插件管理

[英]Gradle plugin management

I'm trying to configure the plugin management for Gradle project to retrieve the plugin dependencies from Nexus.我正在尝试为 Gradle 项目配置插件管理,以从 Nexus 检索插件依赖项。

I have the following line as the first block in the settings.gradle file我将以下行作为 settings.gradle 文件中的第一个块

pluginManagement {
    repositories {
        if (project.hasProperty('kkvmvn')) {
            maven {
              url "${kkvmvn}"
            }
        } else {
            mavenLocal()
            mavenCentral()
            gradlePluginPortal()
        }
    }
}

However, I'm getting the following error但是,我收到以下错误

Caused by: groovy.lang.MissingPropertyException: Could not get unknown property 'project' for repository container of type org.gradle.api.internal.artifacts.dsl.DefaultRepositoryHandler.

Basically I need to access the command line parameter to set the Nexus URL.基本上我需要访问命令行参数来设置 Nexus URL。 How do I do this in settings.gradle file?如何在 settings.gradle 文件中执行此操作? AFAIK it isn't possible to declare plugin repository in build.gradle file. AFAIK 无法在 build.gradle 文件中声明插件存储库。 Here is example how I retrieve other library dependencies in build.gradle这是我如何在 build.gradle 中检索其他库依赖项的示例

subprojects {
    // Java Version JDK 8
    sourceCompatibility = 1.8
    targetCompatibility = 1.8

    tasks.withType(JavaCompile) {
        options.encoding = 'UTF-8'
    }

    repositories {
        if (project.hasProperty('kkvmvn')) {
            maven {
              url "${kkvmvn}"
            }
        } else {
            mavenLocal()
            mavenCentral()
        }
    }
}

In case this helps anyone else, gradle properties can be accessed in settings.gradle using the Settings object.如果这对其他人有帮助,可以使用设置object 在settings.gradle中访问 gradle 属性。gradle。 So a conditional way to set plugin repositories would look something like this:因此,设置插件存储库的条件方法如下所示:

pluginManagement {
    repositories {
        if (settings.hasProperty('kkvmvn')) {
            maven {
              url settings.kkvmvn
            }
        } else {
            mavenLocal()
            mavenCentral()
            gradlePluginPortal()
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM