Explore converting org.gradle.api.Script to Kotin #6686
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Signed-off-by: Jonathan Leitschuh Jonathan.Leitschuh@plexxi.com
Context
I was exploring why the
KotlinBuildScript
, theKotlinSettingsScript
, and theKotlinInitScript
don't have a common interface between them even though they all have exactly the same methods on them.During that exploration I bumped into this comment here on
org.gradle.kotlin.dsl.provider.ScriptApi
Link to real comment:
https://github.com/gradle/kotlin-dsl/blob/0eccacca4c9f87be19dd88045c2007ae3ee58f2f/subprojects/provider/src/main/kotlin/org/gradle/kotlin/dsl/provider/ScriptApi.kt#L36-L48
The primary reason that this is the case is because of the methods:
getLogger
,getLogging
andgetResources
. If you override them in Kotlin you force API consumers to callgetLogger
instead of being able to just dologger
.The "simple" fix for this would be to convert some of the Gradle based interfaces that have these getters to Kotlin.
I decided to start with
Script
because if it were implemented in Kotlin thenKotlinBuildScript
,KotlinSettingsScript
, andKotlinInitScript
would all have a common interface.This would allow for supporting a fourth kind of script (let's call it
KotlinCommonScript
and lets propose the extension*.common.gradle.kts
) that can be applied to any of the aforementioned script types.Current Pain
If you want to have one Gradle Kotlin script that can be called both by a
*.settings.gradle.kts
or.gradle.kts
file you need this kind of nastiness to support both:By converting some of the common interfaces in the Gradle API to Kotlin these sort of issues with collisions between java interface getters and kotlin interface properties can be totally alleviated.
Known Issues
The only problem I can think of off the top of my head is that this will totally break the documentation generation for any files converted to Kotlin.
Contributor Checklist
<subproject>/src/integTest
) to verify changes from a user perspective<subproject>/src/test
) to verify logic./gradlew <changed-subproject>:check
(no joke, it just worked!)Gradle Core Team Checklist