简体   繁体   中英

Gradle plugin management

I'm trying to configure the plugin management for Gradle project to retrieve the plugin dependencies from Nexus.

I have the following line as the first block in the settings.gradle file

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. How do I do this in settings.gradle file? AFAIK it isn't possible to declare plugin repository in build.gradle file. Here is example how I retrieve other library dependencies in 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. 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()
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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