Skip to content

Conversation

@aSemy
Copy link
Contributor

@aSemy aSemy commented Mar 1, 2023

As part of preparatory refactoring for #88, this PR splits up the signature-generator project and Gradle-plugin into two separate projects.

Description

Because Gradle plugins must use Gradle's embedded version of Kotlin, splitting up the projects means the BCV Gradle plugin can be built using/targetting Gradle's embedded Kotlin, while the signature-generator can be built using another version of Kotlin.

It also means that the BCV Gradle plugin can use the kotlin-dsl plugin, which adds some Gradle specific configuration to help plugin development, but is not necessary in the signature-generator.

Splitting up the projects also helps prepare for using the Gradle Worker API, so when the BCV Gradle plugin runs the signature-generator it can specifically control the dependencies used, and potentially default to kotlinx-metadata dependency provided by KGP (if present).

Summary of changes

  • signatures-generator contains the JVM code, and is built using the standard KGP
  • gradle-plugin contains only the Gradle Plugin code, and is built using Gradle's embedded-Kotlin
  • Configuration between the two projects is shared using convention-plugins
  • refactored Maven publication build config to use more Gradle idiomatic functionality, and because the signing plugin is flaky.
  • I put them together in ./modules dir. It's a personal convention that I use a lot of my projects, because it's nice that the built libraries are together under one directory and not mixed up with other build/gradle/IDE/git directories.

Breaking changes

There should be no functional changes from this PR - the plugin and library should work exactly as before, however

  • there are now two new artifacts instead of one
  • The Gradle plugin ID is the same, so users who use the plugins {} DSL just need to bump the version.
  • Because the signature-generator can only be published to Maven Central, and the default repository for plugins is gradlePluginPortal(), the BCV Gradle plugin won't be able to fetch the signature-generator by default

TODO

  • UPDATE: not an issue - GPP proxies Maven Central
    Because the signature-generator can only be published to Maven Central, and the default repository for plugins is gradlePluginPortal(), the BCV Gradle plugin won't be able to fetch the signature-generator by default. There are a few ways around this:

  • There are now two new artifacts, and the old one will continue to exist. Do you want to publish Maven relocation information?

Dependencies

This PR depends on

@aSemy aSemy force-pushed the feat/split_projects branch from 30b7e24 to 4366602 Compare March 1, 2023 13:51
@aSemy aSemy mentioned this pull request Mar 1, 2023
@aSemy aSemy changed the base branch from master to bcv-gradle-rework March 3, 2023 13:49
@aSemy aSemy marked this pull request as ready for review April 27, 2023 08:30
aSemy added 2 commits May 1, 2023 17:50
- bump Gradle Plugin Publish Plugin version
- build script updates & improvements
- use Java Toolchains to set the Java version
- use jvm-test-fixtures plugin for functionalTest sources
- update build config, remove redundant Maven publication
@qwwdfsad qwwdfsad force-pushed the bcv-gradle-rework branch from b5e0510 to 3bec20a Compare May 1, 2023 15:50
aSemy added 12 commits May 1, 2023 18:53
- bump Gradle Plugin Publish Plugin version
- build script updates & improvements
- use Java Toolchains to set Java version
- use jvm-test-fixtures plugin for functionalTest sources
- create convention plugins for common and java-specific config
- add Gradle version catalog
- simplify some build config
…ects

- create new convention plugins
  - kotlin-gradle-plugin, for building Gradle plugins written in Kotlin
  - kotlin-jvm, for building Kotlin/JVM projects
  - maven-publishing, for sharing common maven-publish settings
- update gitignore, because `build/` dirs might be nested, and to include common IDE/OS property/language files
@aSemy aSemy force-pushed the feat/split_projects branch from 6fb9d87 to 3c61170 Compare May 1, 2023 18:25
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The configuration in this file was moved to buildSrc convention plugins, so that it could be shared between the two new subprojects as appropriate.

groovy.setSrcDirs(emptyList<String>())
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion") {
because("allows applying the `kotlin-dsl` / `embedded-kotlin` plugins in buildSrc convention plugins")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I know you like removing the unnecessary src/main dirs, but in this case I thought it was extra configuration that didn't really bring much. Given how Gradle can be quite fragile, and how IntelliJ has tenuous support of buildSrc as it is, I thought it was better remove anything not strictly necessary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It brings a flat folder structure that we would like to embrace everywhere and get rid of the legacy nested format. Dogfooding and reporting all the problems in the process in an important part here.

I'm okay with this change and can tweak it later after all the merges though

aSemy added 5 commits May 2, 2023 17:50
- create convention plugins for common and java-specific config
- add Gradle version catalog
- simplify some build config
* The ABI shape will be reduced in the future, this is a technical change
@qwwdfsad qwwdfsad self-requested a review May 4, 2023 14:51
@qwwdfsad
Copy link
Member

Sorry for the delay here, it's a planning time in Kotlin, so I fail to spare a decent chunk of continuous time to get back on it.
Next week hopefully!

@aSemy
Copy link
Contributor Author

aSemy commented May 26, 2023

No probs. This is a big change so take your time 👍

@qwwdfsad
Copy link
Member

qwwdfsad commented Jun 29, 2023

I've asked my colleague to help with the Gradle part, he mentioned the following potential caveats:

  1. Compilation with embedded Kotlin might lead to LV/AV issues: e.g. with Gradle 8, embedded Kotlin immediately sets LV 1.8, rendering the plugin unusable with Gradle 6.9+. Probably can be fixed with explicit LV/AV for compilation

  2. "the BCV Gradle plugin won’t be able to fetch the signature-generator by default". If I got this right, it's not an issue, because GPP proxies maven central as well

  3. It's an open question (and it's unclear whether it's an issue at all) how to compile Gradle plugin against signatures-generator built with too new Kotlin version

@aSemy
Copy link
Contributor Author

aSemy commented Jul 1, 2023

I've asked my colleague to help with the Gradle part, he mentioned the following potential caveats:

  1. Compilation with embedded Kotlin might lead to LV/AV issues: e.g. with Gradle 8, embedded Kotlin immediately sets LV 1.8, rendering the plugin unusable with Gradle 6.9+. Probably can be fixed with explicit LV/AV for compilation

Gradle Test Kit has been set to use Gradle 7.4.2 and the tests seems to work fine (although I don't really understand how or why...).

  1. "the BCV Gradle plugin won’t be able to fetch the signature-generator by default". If I got this right, it's not an issues, because GPP proxies maven central as well

Ah okay, interesting, thanks! And also, now that I think about it, it has to be the case. Lots of Gradle plugins depend on non-plugin dependencies, and they work fine. BCV depends on the Kotlin stdlib already, and that must come from Maven Central.

  1. It's an open question (and it's unclear whether it's an issue at all) how to compile Gradle plugin against signatures-generator built with too new Kotlin version

Yes, good point. I expect that any problems would be picked up by the Gradle Test Kit test. Also, any further incompatibility problems would be reduced in the future by my plan to use a Gradle Worker to run signatures-generator in an isolated classpath.

Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, and sorry for the delay!

I gave it one more look, and it seems good in general
I have a few questions and an issue with non-conventional Gradle DSL and Maven Coordinates issue and I think it will be good to go

groovy.setSrcDirs(emptyList<String>())
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion") {
because("allows applying the `kotlin-dsl` / `embedded-kotlin` plugins in buildSrc convention plugins")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It brings a flat folder structure that we would like to embrace everywhere and get rid of the legacy nested format. Dogfooding and reporting all the problems in the process in an important part here.

I'm okay with this change and can tweak it later after all the merges though

}

tasks.validatePlugins {
//enableStricterValidation.set(true) // TODO enable validation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on when it's okay to enable it to what the blockers are?



// the signing plugin must be configured *after* publications are created
afterEvaluate {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please elaborate on why we have to rely on afterEvaluate even though previously it was not the case?

I'm a bit concerned here as the afterEvaluate block always causes troubles in the long run, as more and more workarounds start piling there (esp. with AGP present)



@Suppress("UnstableApiUsage")
gradlePlugin {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave local publication a go:

  1. On conventionally-configured Gradle projects with Kotlin DSL and plugins everything is really smooth

  2. On groovy DSL old-way (kotlinx.coroutines 😄 ) I failed to depend on the plugin:

  • The plugin is published to ~/.m2/repository/org/jetbrains/kotlinx/binary-compatibility-validator/org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin/ which cannot be dependent on as is
  • I've checked out the resulting POM, and its coordinates are the following:
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>gradle-plugin</artifactId>
<version>0.14.0-qtest</version>

Two points here:

  1. gradle-plugin is not really a good name in kotlinxnamespace, I suggest renaming it to something more specific, e.g.bcv-gradle-pluginorbinary-compatibility-validator-gradle-plugin`
  2. Figuring this out is hard and (we already had this in Kover) will lead to a lot of questions "how to upgrade with classpath dependency"; let's publish maven relocation information

@qwwdfsad
Copy link
Member

qwwdfsad commented Sep 18, 2023

Also, if it works for you, could you please update Kotlin to 1.9.0 alongside this change?

@qwwdfsad qwwdfsad deleted the branch Kotlin:bcv-gradle-rework January 12, 2024 14:22
@qwwdfsad qwwdfsad closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants