Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
An initscript to apply gradle plugins globally
/*
This must be added to ~/.gradle/init.gradle or to a .gradle file under ~/.gradle/init.d/ before applying.
initscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.dvoiss.globalplugins:global-gradle-plugin:1.0-SNAPSHOT"
}
}
*/
// This will be easier once the following ticket is fixed:
// https://issues.gradle.org/browse/GRADLE-2407, "Cannot load custom plugin to project from an init script"
// We have to use the fully-qualified class name to apply the plugin
// instead of the plugin ID due to a known issue in gradle:
// https://discuss.gradle.org/t/how-do-i-apply-a-plugin-to-a-project-from-a-shared-applied-gradle-file/7508/2
// apply the plugin before using the globalDependencies closure
apply plugin: com.dvoiss.globalplugins.GlobalDependencyPlugin
// add dependencies to all projects
allprojects {
globalDependencies {
// repos for plugins added below, add other repos including mavenLocal() for local plugins
repos {
jcenter()
}
// add <PLUGIN CLASSPATH>, <PLUGIN ID>, <OPTIONAL "AFTER PLUG-IN" PREDICATE>
add "de.hannesstruss:godot:+", 'de.hannesstruss.godot'
// android dependencies, should only be applied after one of the android plugin (or else an error will occur)
def androidPlugins = [ 'com.android.build.gradle.AppPlugin', 'com.android.build.gradle.LibraryPlugin', 'com.android.build.gradle.TestPlugin' ]
def afterAndroidPluginPredicate = { plugin -> androidPlugins.contains(plugin) }
add 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.2', 'com.getkeepsafe.dexcount', afterAndroidPluginPredicate
// special short-hand for Android, this does the same thing as above
addAndroid 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:0.4.2', 'com.getkeepsafe.dexcount'
}
}
@dvoiss

This comment has been minimized.

Copy link
Owner Author

@dvoiss dvoiss commented Mar 14, 2016

NOTE:
If I want to keep my setup minimal, I can use a remote script like the above.

In the file ~/.gradle/init.d/global-plugins.gradle I can apply this remotely. The initscript cannot be used inside the "applied from" closure and has to be in the file:

initscript {
    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }
    dependencies {
        classpath "gradle.plugin.com.dvoiss.globalplugins:global-gradle-plugin:1.0-SNAPSHOT"
    }
}

// APPLY THE GIST ABOVE
apply from: "https://gist.githubusercontent.com/dvoiss/37cb797b42a00a9a2db6/raw/050f9a9c7acf353af6d7427cfa7daecd6a144e9c/remote-global-plugin-script.gradle"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment