Using Plugin functionality in buildscript

plugins

(William Carter) #1

Hello,

Is it possible to use a plugin within a root project’s buildscript section? I need to be able to do this in order to define how my other plugins should be resolved.

I’m using the gradle-credentials-plugin to set a maven_password property so I can define my own maven repository. The plugin then provides a credentials object which can be accessed in the build script. Here is a broken example of the kind of thing I’m trying to do:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath('nu.studer:gradle-credentials-plugin:1.0.4')
    }

    apply plugin: 'nu.studer.credentials'

    String maven_password = credentials.maven_password // from gradle-credentials-plugin
    repositories {
        maven {
            url maven_url // from ~/.gradle/gradle.properties
            credentials {
                username = maven_user // from ~/.gradle/gradle.properties
                password = maven_password
            }
        }
    }
    dependencies {
        classpath('carter.will:custom-plugin:1.0.0')
    }
}

Thank you very much for any assistance.
Will


(James Justinic) #2

This isn’t really possible with this plugin as it stands since it can only be applied to a Project and you need the buildscript classpath to be resolved first with the plugin before you can use it.

If you wanted to create a wrapper project only for this purpose, it would work, but that means your current root project would have to be a subproject of this new root.

One other possibility is if you converted the plugin to be applied in an initscript or settings.gradle, it just might be soon enough, but I haven’t tried this.