Last active
November 1, 2022 15:10
-
-
Save dvoiss/37cb797b42a00a9a2db6 to your computer and use it in GitHub Desktop.
An initscript to apply gradle plugins globally
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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. Theinitscript
cannot be used inside the "applied from" closure and has to be in the file: