Martin
09/07/2024, 5:03 PMjava-gradle-plugin use a custom publication? The doc says
This automatic configuration happens in a Project.afterEvaluate() block (so at the end of the build configuration phase), and only if these publications haven't already been defined, so it's possible to create and customise them during the earlier stages of build configuration
But no matter what, the "java" component is added and the build fails with
Maven publication 'pluginMaven' cannot include multiple components
Can I tell java-gradle-plugin to use another component than the java one?Adam
09/07/2024, 5:11 PMgradlePlugin {
isAutomatedPublishing = false
}
https://github.com/gradle/gradle/blob/ebfcf97806a2c04b870652374bcbee2c915dac93/platforms/extensibility/plugin-development/src/main/java/org/gradle/plugin/devel/plugins/MavenPluginPublishPlugin.java#L66-L68Martin
09/07/2024, 5:12 PMMartin
09/07/2024, 5:14 PMMartin
09/07/2024, 5:14 PMjava-gradle-pluginAdam
09/07/2024, 5:15 PMAdam
09/07/2024, 5:15 PMkotlin-gradle-pluginMartin
09/07/2024, 5:16 PMjava-gradle-plugin :
⢠generation of the resource file
⢠creation of the plugin markerMartin
09/07/2024, 5:16 PMkotlin-gradle-plugin do on top of that?Adam
09/07/2024, 5:19 PMtasks.withType<PublishToMavenRepository>().configureEach {
onlyIf { publication.name != "pluginMaven" }
}Martin
09/07/2024, 5:20 PMMartin
09/07/2024, 5:21 PMAdam
09/07/2024, 5:22 PMkotlin-gradle-plugin would do the same as kotlin-dsl, but without the precompiled script plugins. And strongly encourage all of the best practice https://github.com/gradle/gradle/pull/24286Martin
09/07/2024, 5:22 PMMartin
09/07/2024, 5:24 PMAdam
09/07/2024, 5:24 PMAdam
09/07/2024, 5:26 PMMartin
09/07/2024, 5:27 PMVampire
09/07/2024, 5:36 PMMartin
09/07/2024, 5:44 PMVampire
09/07/2024, 5:46 PMrelocated you probably mean you use the shadow plugin to create a fat jar and want to publish that instead?Vampire
09/07/2024, 5:47 PMMartin
09/07/2024, 5:47 PMMartin
09/07/2024, 5:47 PMMartin
09/07/2024, 5:47 PMshadow cannot relocate the kotlin stdlibMartin
09/07/2024, 5:48 PMVampire
09/07/2024, 5:49 PMplugin-publish plugin has built-in support for the shadow plugin and will automatically publish that one.
Ah, so you just obfuscate your code with R8?
Or what is it? Just heard of it in relation to Android builds.
If so, why do you do it? Maven Central only accepts open source libs anyway, doesn't it?Martin
09/07/2024, 5:51 PMAh, so you just obfuscate your code with R8?Just relocate to avoid classloader issues, no obfuscation. R8 is designed for Android but it works with .class files too
Martin
09/07/2024, 5:51 PMMaven Central only accepts open source libs anyway, doesn't it?Fun fact, Maven Central doesn't care. You can publish an empty source jar and it's fine
Vampire
09/07/2024, 5:51 PMVampire
09/07/2024, 5:52 PMMartin
09/07/2024, 5:52 PMMartin
09/07/2024, 5:52 PMVampire
09/07/2024, 5:53 PMMartin
09/07/2024, 5:53 PMVampire
09/07/2024, 5:54 PMMartin
09/07/2024, 5:54 PMMartin
09/07/2024, 5:54 PMWill that then not cause problems still as Gradle still controls the Kotlin execution environment / Kotlin version used?That's the thing, I can use Kotlin 2 in my plugin without any fear š
Martin
09/07/2024, 5:55 PMMartin
09/07/2024, 5:55 PMVampire
09/07/2024, 6:32 PMconstraint to update the ASM version when you for example use a version that does not support some class file version that the user is needing. I for example did this for the dependency analysis Gradle plugin. That also uses a relocated asm, but at least packaged and depended on as separate artifact, so I could update it without updating the plugin which was not possible for other reasons.
But I thought relocating Kotlin stdlib like that will not be sufficient as Gradle still controls which Kotlin version that is used to execute it.
Well, as long as it is a Gradle version with Kotlin 1.9 it will probably be able to use the Kotlin 2.0 stdlib because of the one version forward compatibility guarantee, but I'm not sure whether that's really worth the effort and you can still not run then on Gradle version before 8.3.0. š
That's why I personally would never use Kotlin or Groovy to implement a public Gradle plugin, but always just Java and there lowest version supported by the lowest Gradle version I want to support to have best compatibility. šVampire
09/07/2024, 6:35 PMYea but I'd like the marker to use my own publication instead of the default oneIf your custom publication is published to the same coordinates the automatic publication would have, where is the problem? The marker depends on coordinates.
Vampire
09/07/2024, 6:36 PMjava component to have what you wantVampire
09/07/2024, 6:36 PMMartin
09/07/2024, 6:37 PMconstraint to update the ASM version when you for example use a version that does not support some class file version that the user is needing.
True
> I thought relocating Kotlin stdlib like that will not be sufficient as Gradle still controls which Kotlin version that is used to execute it.
Apollo has been using more recent kotlin version for several years now, it's working fine.
> because of the one version forward compatibility
That's at compile time. At runtime, if your plugin uses a K2 symbol, it'll crash (latest example)Martin
09/07/2024, 6:38 PMMartin
09/07/2024, 6:39 PMIf your custom publication is published to the same coordinates the automatic publication would have, where is the problem?It's mainly an aesthetics problem but not only. Now I have 2 publications overwriting each other. Someone calling
publishAllPublications... will see a bunch of warnings, potentially use the wrong one, etc...Vampire
09/07/2024, 6:41 PMMartin
09/07/2024, 6:41 PMVampire
09/07/2024, 6:41 PMjava component if possible šMartin
09/07/2024, 6:42 PM