Slackbot
11/04/2023, 5:56 AMJavi
11/04/2023, 6:19 AMimplementation configuration.
Does your plugin do something with any KGP API?Jakub Chrzanowski
11/04/2023, 6:27 AMKotlinCompile class I just read the kotlinOptions property to get:
kotlinOptions.jvmTarget
kotlinOptions.apiVersion
kotlinOptions.languageVersion
The problem is that I’ll have to explicitly specify Kotlin version. OTOH, I’m already locked to the version I use for building the plugin…Javi
11/04/2023, 6:29 AMJakub Chrzanowski
11/04/2023, 6:32 AMJavi
11/04/2023, 6:38 AMJakub Chrzanowski
11/04/2023, 7:08 AMephemient
11/04/2023, 7:59 AM.withGroovyBuilder { } in the Kotlin DSL), you can interact with types that aren't in your classpath (stringly-typed via reflection)Thomas Broyer
11/04/2023, 11:17 AMcompileOnly.
…either that or change your plugin to apply the Kotlin plugin (with the version you're depending on) and remove the explicit application from the build script.Thomas Broyer
11/04/2023, 11:18 AMversion "1.9.10" from the build script so it uses the version brought in by your plugin)Vampire
11/04/2023, 12:15 PMcompileOnly, that's why the Kotlin plugin is not together with his plugin in the settings class loader and why his plugin classes cannot access the Kotlin classes which are on the build scritp class loader which is a child.Vampire
11/04/2023, 12:17 PMVampire
11/04/2023, 12:18 PMVampire
11/04/2023, 12:19 PMwithGroovyBuilder @ephemient suggested, or plain old reflection.Javi
11/04/2023, 12:22 PMcheck that the versions of project and settings plugin matchAs I think he is talking about the IntelliJ Gradle plugin, I think the Kotlin version should be defined by the user, so I am not sure if that can be a problem to get the same version in both plugins.
Javi
11/04/2023, 12:28 PMabstract class IntelliJPlatformSettingsPlugin @Inject constructor(
private val objects: ObjectFactory,
private val providers: ProviderFactory,
) : Plugin<Settings> {
override fun apply(settings: Settings) {
settings.dependencyResolutionManagement.repositories.applyIntelliJPlatformSettings(objects, providers)
}
}
interface IntelliJPlatformRepositorySettings {
val useCacheRedirector: Property<Boolean>
}
internal fun RepositoryHandler.applyIntelliJPlatformSettings(objects: ObjectFactory, providers: ProviderFactory) {
val settings = objects.newInstance(IntelliJPlatformRepositorySettings::class)
settings.useCacheRedirector.convention(BuildFeature.USE_CACHE_REDIRECTOR.getValue(providers))
(this as ExtensionAware).extensions.add(Extensions.INTELLIJ_PLATFORM_REPOSITORY_SETTINGS, settings)
}
It looks like you can create a shared module to put that interface and/or the utility function, splitting the plugins into two projects. Obviously, it will be a bit annoying but I think it is the cleanest way.Vampire
11/04/2023, 12:29 PMAs I think he is talking about the IntelliJ Gradle plugin, I think the Kotlin version should be defined by the user, so I am not sure if that can be a problem to get the same version in both plugins.I'm not talking about the Kotlin version. I'm talking about the versions of his project plugin and his settings plugin. If he splits them into two like you and me suggested, it would be possible to apply different versions of the two plugins, and this should most likely be prevented.
Javi
11/04/2023, 12:30 PMJakub Chrzanowski
11/06/2023, 11:53 AMMySettingsPlugin is supposed to let you only add custom repositories to dependencyResolutionManagement — no more logic should be involved there.
Same repositories are supposed to be added in the Project-level configuration with repositories {} block.
Both use now the same code which is implemented using ExtensionAware — because of that, I’d like to avoid splitting project into two parts.
In the snippet @Javi shared (yes, it’s all about IntelliJ Platform Gradle Plugin 2.0), I was still using Kotlin extension functions.
As for now — thanks to ExtensionAware approach, I dropped this IntelliJPlatformRepositorySettings magic as all required objects are `@Inject`ed now properly.
This refactoring revealed that KotlinCompile is actually called on the Settings-level, which became a blocker.
Any tricks to import Kotlin dependency or reflections aren’t something I’d like to rely on. Also to don’t bring anything to the project (especially as crucial as Kotlin) without user’s knowledge. They still should be able to build the plugin with no Kotlin involved.
I like the withGroovyBuilder approach, even though it relies on Groovy magic — but for such a small tasks it fits perfectly — and I was able to successfully implement it with no more exceptions on the Settings-level.
Thanks so much, folks!Jakub Chrzanowski
11/06/2023, 11:55 AMVampire
11/06/2023, 1:07 PMwithGroovyBuilder is actually also just using reflection with added Groovy syntactic sugar. 🙂
So whatever feels better for you. :-)Jakub Chrzanowski
11/06/2023, 1:27 PM