Slackbot
10/26/2023, 2:46 PMVampire
10/26/2023, 3:21 PMorg.gradle namespace.
But as long as Gradle does not run on the module path where split packages are disallowed, it should work.
Instead I would suggest you do not provide Kotlin extension functions, but create a Gradle extension on those containers and have the methods in that extension. Then it also works without import and even works the same for Groovy DSL and Kotlin DSL consumers.Vampire
10/26/2023, 3:31 PMRepositoryHandler not formally declaring it is ExtensionAware.
Practically any Gradle model class and also all classes you let Gradle create from any other plugin is dynamically decorated to be ExtensionAware.
Just use (repositories as ExtensionAware). and you can still add extensions and for both of these containers you also get type-safe accessors generated for Kotlin DSL:Jakub Chrzanowski
10/26/2023, 3:33 PMorg.gradleJakub Chrzanowski
10/26/2023, 3:33 PMrepositories {
intellijPlatform.intellij()
mavenCentral()
intellijPlatform.intellijSnapshots()
}
Note that order matters here.Jakub Chrzanowski
10/26/2023, 3:34 PMPaul Merlin
10/26/2023, 3:34 PMPaul Merlin
10/26/2023, 3:34 PMVampire
10/26/2023, 3:34 PMJakub Chrzanowski
10/26/2023, 3:35 PMVampire
10/26/2023, 3:35 PMrepositories {
intellijPlatform {
intellij()
mavenCentral()
intellijSnapshots()
}
}
I think.
The mavenCentral() should automatically be called on the outer scopeVampire
10/26/2023, 3:36 PMbut still… I need something for now.So? What I described should work on older versions too I think.
Jakub Chrzanowski
10/26/2023, 3:37 PMVampire
10/26/2023, 3:37 PMrepositories {
the<IntellijPlatformRepoExtension>().intellij()
mavenCentral()
the<IntellijPlatformRepoExtension>().intellijSnapshots()
}
if someone needs to use an older version and Kotlin DSLVampire
10/26/2023, 3:37 PMVampire
10/26/2023, 3:38 PMI was referring to issue from PaulAh, ok, yeah. Imho an extension is anyway better than a default import for the cases you described as it then works for Groovy and Kotlin alike
Vampire
10/26/2023, 3:38 PMJakub Chrzanowski
10/26/2023, 3:40 PMrepositories {
intellijPlatform.intellij()
}
dependencies {
intellijPlatform.intellijIdeaCommunity("2023.2.2")
}
intellijPlatform {
pluginConfiguration {
id = properties("pluginId")
name = properties("pluginName")
...
}
// ... other options TBD
}Jakub Chrzanowski
10/26/2023, 3:40 PMVampire
10/26/2023, 3:41 PMJakub Chrzanowski
10/26/2023, 3:44 PMJakub Chrzanowski
10/26/2023, 3:45 PMJakub Chrzanowski
10/26/2023, 3:46 PMJakub Chrzanowski
10/26/2023, 3:47 PMVampire
10/26/2023, 4:02 PMrepositories container or project as constructor argument for example.
But anyway it imho is very questionable to add repositories unasked and non-optional.
That will fail with repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) and make it harder to fulfill guidelines like "only use in-house maven repository mirrors".Jakub Chrzanowski
10/26/2023, 4:25 PMVampire
10/26/2023, 4:37 PMFAIL_ON_PROJECT_REPOS, wouldn't it?Vampire
10/26/2023, 4:37 PMJakub Chrzanowski
10/26/2023, 4:38 PMVampire
10/26/2023, 4:39 PMVampire
10/26/2023, 4:39 PMVampire
10/26/2023, 4:40 PMrepositories container or project to the constructor args when you let Gradle create your extension and it should probably workJakub Chrzanowski
10/26/2023, 4:40 PMJakub Chrzanowski
10/26/2023, 4:41 PMJakub Chrzanowski
10/26/2023, 4:42 PMVampire
10/26/2023, 4:45 PMthe<IJPExtension>().addRepo() syntax I mentioned above when using the extension route and Kotlin DSL.Vampire
10/26/2023, 4:51 PMorg.gradle namespace. I personally don't have problems with imports from Plugins I use.Jakub Chrzanowski
11/03/2023, 11:14 AMdependencyResolutionManagement {
repositories {
(this as ExtensionAware).the<IntelliJPlatformRepositoriesExtension>().releases()
}
}Jakub Chrzanowski
11/03/2023, 11:15 AMthe refers to object other than RepositoryHandlerVampire
11/03/2023, 12:23 PMRepositoryHandler does not officially declare ExtensionAware 😞
So at least for the settings script a custom accessor probably makes sense.Vampire
11/07/2023, 11:33 AMintellijPlatform, we said in Groovy DSL you can just do
intellijPlatform {
// ...
}
but with Kotlin DSL you do not get typesafe accessors created, so you would need to use something like
import org.jetbrains.IntelliJPlatformSettingsExtension
configure<IntelliJPlatformSettingsExtension) {
// ...
}
Or with manually provided accessor outside org.gradle namespace like
package org.jetbrains
val Settings.intellijPlatform: IntelliJPlatformSettingsExtension
get() = extensions.getByName("intellijPlatform") as IntelliJPlatformSettingsExtension
fun Settings.intellijPlatform(configuration: Action<IntelliJPlatformSettingsExtension>): Unit =
extensions.configure("intellijPlatform", configuration)
you could have
import org.jetbrains.intellijPlatform
intellijPlatform {
// ...
}
That's what we had so far.
But if the import is what bugs you most, you can also simply tell the users to use fully-qualified:
org.jetbrains.intellijPlatform {
// ...
}Jakub Chrzanowski
11/07/2023, 11:36 AMfun RepositoryHandler.intellijPlatform(configure: Action<IntelliJPlatformRepositoriesExtension>) =
(this as ExtensionAware).the<IntelliJPlatformRepositoriesExtension>().apply(configure::execute)
and this is fine to have single import for this particular case.
What I wanted to avoid is a bloated import section in a daily-basis work for regular users.Vampire
11/07/2023, 11:45 AMfun RepositoryHandler.intellijPlatform(configure: Action<IntelliJPlatformRepositoriesExtension>) =
(this as ExtensionAware).extensions.configure("intellijPlatform", configure)
the is more meant to get the extension, not to configure it.
And with the extensions.configure you also configure by type and name to be sure you are configuring the intended extension.
Otherwise if someone would have the strange idea to register a second extension of that type, it would fail iirc.Jakub Chrzanowski
11/07/2023, 11:55 AM