Slackbot
05/04/2022, 6:04 PMZak Taccardi
05/04/2022, 6:06 PMChris Lee
05/04/2022, 6:06 PMfun Project.prohibitPlugin(pluginId: String, message: String) {
withPlugin(pluginId) {
throw GradleException("Plugin prohibited: $pluginId; $message")
}
}
fun Project.withPlugin(pluginId: String, action: Action<AppliedPlugin>) {
pluginManager.withPlugin(pluginId, action)
}
inline fun <reified S : Plugin<Project>> Project.withPlugin(noinline configuration: S.() -> Unit) {
plugins.withType<S>(configuration)
}
override fun apply(project: Project): Unit = project.run {
// shortcut for plugins.withType<>
withPlugin<MavenPublishPlugin> {
configure<PublishingExtension> {
publications {
create<MavenPublication>("javaLibrary") {
from(components["java"])
}
}
}
}
}Zak Taccardi
05/04/2022, 6:09 PMpluginManager.withId(..) over plugins.withType<PluginClass>()?Chris Lee
05/04/2022, 6:10 PMChris Lee
05/04/2022, 6:12 PMtony
05/04/2022, 6:12 PMZak Taccardi
05/04/2022, 6:13 PMtony
05/04/2022, 6:13 PMtony
05/04/2022, 6:13 PMChris Lee
05/04/2022, 6:16 PMChris Lee
05/04/2022, 6:17 PMThomas Broyer
05/04/2022, 6:59 PMplugins { id("…") }, apply(plugin = "…") .
There's no real reason to use the class as an identifier.Chris Lee
05/04/2022, 7:02 PMephemient
05/04/2022, 7:21 PMChris Lee
05/04/2022, 7:25 PMpluginManager.withPlugin("org.something.somePlugin") when invariably you need the various API classes from the plugin anyhow. Sure, you could define a constant for that - but that’s not only extra work, it needs to be repeated across multiple places (have dozens of plugins that use MavenPublishPlugin, bringing in consistency of naming that constant, etc.) Use the plugin class and embrace the type safety.Chris Lee
05/04/2022, 7:33 PMtony
05/04/2022, 7:51 PMChris Lee
05/04/2022, 7:54 PMThomas Broyer
05/05/2022, 8:05 AM