Javi
10/08/2024, 11:30 AMpublic class SemverSettingsPlugin : Plugin<Settings> {
override fun apply(target: Settings) {
target.gradle.beforeProject { project ->
project.pluginManager.apply(SemverProjectPlugin::class)
}
}
}
As I am applying it via SemverProjectPlugin::class, any try to use plugin.manager.withPlugin("com.javiersc.semver") is not working.
Am I forced to apply the plugin via ID? Is it possible to apply it in both ways or link the ID somehow?Vampire
10/08/2024, 11:33 AMJavi
10/08/2024, 11:38 AMprintSemverJavi
10/08/2024, 11:41 AMgradle.afterProject { project ->
println("Project: ${project.name}")
project.pluginManager.withPlugin('com.javiersc.semver') {
println("Plugin: com.javiersc.semver is applied")
project.extensions.configure(SemverExtension) { semver ->
semver.mapVersion Map.per
}
}
}
The Plugin: com.javiersc.semver is applied is only shown for the projects that explicitly apply the plugin.
Can the implementation break the mapping?
⢠https://github.com/JavierSegoviaCordoba/semver-gradle-plugin/blob/c402c81e05b77cb34315c23c89e2ee312a218b8d/semver-settings-gradle-plugin/main/kotlin/com/javiersc/semver/settings/gradle/plugin/SemverSettingsPlugin.kt#L8-L15
⢠https://github.com/JavierSegoviaCordoba/semver-gradle-plugin/blob/c402c81e05b77cb34315c23c89e2ee312a218b8d/semver-gradle-plugin/main/kotlin/com/javiersc/semver/gradle/plugin/SemverPlugin.kt#L13-L17Vampire
10/08/2024, 11:45 AMSemverPlugin does have that ID, not SemverProjectPluginVampire
10/08/2024, 11:46 AMSemverSettingsPluginJavi
10/08/2024, 11:48 AMJavi
10/08/2024, 11:54 AMpublic class SemverPlugin : Plugin<PluginAware> {
override fun apply(target: PluginAware) {
when (target) {
is Project -> target.pluginManager.apply(SemverProjectPlugin::class)
is Settings -> target.pluginManager.apply(SemverSettingsPlugin::class)
else -> error("Semver cannot be applied to ${target::class}")
}
}
}Vampire
10/08/2024, 11:55 AMSemverPlugin in your SemverSettingsPluginJavi
10/08/2024, 11:57 AMpluginManager::withPlugin would be for SemverPlugin which is applying other plugins but not doing anything itself?
No weird race conditions or something so?Vampire
10/08/2024, 11:57 AMSemverProjectPlugin and SemverSettingsPlugin don't necessarily need own plugin IDs, unless you want to be able to apply them directly using the respective ID or react to those being applied. If you just consider them an implementation detail, you should also be fine.Vampire
10/08/2024, 11:58 AMCould it not be a problem that the callbackwould be forpluginManager::withPluginwhich is applying other plugins but not doing anything itself?SemverPlugin
No weird race conditions or something so?Well, if you apply one of the sub-plugins directly without applying the delegating plugin, you cannot react using the delegating plugin id. But if you consider them an implementation detail and maybe even make the sub-plugins
internal, I don't think there should be any problems.Javi
10/08/2024, 11:59 AMwhen (target) {
is Project -> target.pluginManager.apply(SemverProjectPlugin::class)
is Settings -> target.pluginManager.apply(SemverSettingsPlugin::class)
else -> error("Semver cannot be applied to ${target::class}")
}
So I think I need to merge those two into oneVampire
10/08/2024, 12:00 PMVampire
10/08/2024, 12:00 PMJavi
10/08/2024, 12:02 PMSemverPlugin belongs to the project semver-gradle-plugin, and it applies SemverSettingsPlugin which belongs to the project semver-settings-gradle-plugin
As the first one needs the second one to do the when I mentioned above, the settings project cannot depend on the project that contains the SemverPluginJavi
10/08/2024, 12:02 PMsemver-gradle-plugin and semver-settings-gradle-plugin into one module to avoid that problemVampire
10/08/2024, 12:03 PMJavi
10/08/2024, 12:04 PMJavi
10/08/2024, 12:05 PMVampire
10/08/2024, 12:12 PMJavi
10/08/2024, 12:22 PMhubdle and hubdleSettings and I think I can have this issue again if try to do the same with semver. I am not sure if the problem was that hubdle was indeed a Kotlin extension function too and not a Gradle extension itself. Have you seen that issue before?
Creating the Kotlin extension for the settings plugin can be problematic on Groovy? I do not use Groovy at all but some users of my plugin are using it so I need to take care with this topic.Vampire
10/08/2024, 12:35 PMJavi
10/08/2024, 12:37 PMJavi
10/08/2024, 1:24 PMVampire
10/08/2024, 1:37 PMconfigure<SemverSettingsExtension> { ... } or use an extension function the plugin provided as no accessors were generated, but since some time you should even get type-safe accessors generated.Vampire
10/08/2024, 1:39 PMJavi
10/08/2024, 1:52 PMJavi
10/08/2024, 2:20 PM