gradle / gradle

Adaptable, fast automation for all
https://gradle.org
Apache License 2.0
16.99k stars 4.77k forks source link

Allow to configure Kotlin compiler options for the build scripts #24221

Open pbielicki opened 1 year ago

pbielicki commented 1 year ago

We'd like to be able to configure Kotlin compiler options for the build scripts (e.g. build.gradle.kts)

Expected Behavior

Gradle exposes an API, DSL or CLI argument that allows to specify Kotlin compiler options e.g. -Werror

Current Behavior

It's currently not possible to configure options for the Kotlin compiler used to compile build scripts (.kts files)

Context

We recently discovered quite some compilation warnings coming from our Kotlin build scripts. We'd like to treat those warnings as errors and fail the build. It would be quite simple task if only we were able to pass -Werror flag to the Kotlin compiler.

eskatos commented 1 year ago

Thank you for your interest in Gradle!

This feature request is in the backlog of the relevant team and is prioritized by them.

bkuchcik commented 1 year ago

I'd like to something similar by enabling an experimental feature for build.gradle.kts.

I'd like to use script with context (in my build.src) and I need to pass the '-Xcontext-receivers' flag to the kotlin compiler.

As I understand it will be possible for the 8.2 RC1

eskatos commented 1 year ago

The compilation of standalone Gradle Kotlin DSL script uses the embedded Kotlin compiler API. At this level the support for compiler argument is only via an API and there is no support for "free compiler arguments" string syntax. Because of this we would need to add explicit support for each supported argument, this is not sustainable.

Going forward, the following might eventually enable us to provide such convenience:


However, now that Gradle 8.1 started to emit the compilation warning on the console, we will add explicit support for -Werror so that folks can configure their build to fail on warnings in order to track them and prevent the introduction of new ones.

mirfatif commented 2 months ago

Any updates?