Skip to content

Fulfill the new requirements for Kotlin User Projects #4392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

dkhalanskyjb
Copy link
Collaborator

No description provided.

* Then, `true` means that warnings should be treated as errors, `false` means that they should not.
*/
private fun warningsAreErrorsOverride(project: Project): Boolean? =
when (val prop = project.rootProject.properties["kotlin_Werror_override"] as? String) {
Copy link
Member

Choose a reason for hiding this comment

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

Probably, should be used API compatible with isolated projects?

Suggested change
when (val prop = project.rootProject.properties["kotlin_Werror_override"] as? String) {
when (val prop = project.providers.gradleProperty("kotlin_Werror_override").orNull) {

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry, but I don't know what the difference is. rootProject.properties is already used throughout our build scripts, and I haven't heard of any issues because of that. Could provide/link to a clear explanation of the downsides of the existing approach?

Copy link
Member

@osipxd osipxd Mar 27, 2025

Choose a reason for hiding this comment

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

Sure!
Calling Project.properties is quite expensive because it collects not only properties from gradle.properties and CLI arguments, but also tasks and their fields, extensions, extras, conventions, etc (see gradle/gradle#25053)
getProperty and hasProperty are better, but they're not compatible with isolated projects because of the access to properties of other projects.

Since you're getting the property from the root project, it should be safe to use providers.gradleProperty which looks for Gradle properties in the root project. As a bonus, this API is compatible with isolated projects (which I hope will be stable someday) as there is no need in calling methods of the rootProject

Copy link
Member

Choose a reason for hiding this comment

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

However, as soon as this syntax is used everywhere in this file, this change is indeed out of the scope of the current PR.

@woainikk
Copy link
Contributor

@dkhalanskyjb can you please also like this?:
Implement a Gradle property for passing additional CLI options to the Kotlin compiler
(property naming is not critical but kotlin_additional_cli_options is suggested for consistency). And the passed kotlin_additional_cli_options should be applied as compiler options

@dkhalanskyjb
Copy link
Collaborator Author

@woainikk, are there examples (either of other libraries doing this or of this property being used)? What exactly is the content of the property? Is it a space-separated list of strings? A comma-separated list? Something else? Should the options go before or after the usual ones (if that's important)?

@woainikk
Copy link
Contributor

woainikk commented Apr 3, 2025

@dkhalanskyjb values are space-separated (quoting values with spaces is not supported);
e.g.: -nowarn -Xwarning-level=CONTEXT_RECEIVERS_DEPRECATED:warning
The options should go after the usual ones

@woainikk
Copy link
Contributor

woainikk commented Apr 3, 2025

@dkhalanskyjb Can you please also add logging to somewhere, to all applied compiler flags were printed to log?

@dkhalanskyjb dkhalanskyjb force-pushed the dkhalanskyjb/configure-Werror branch from bb0d0db to 36b551f Compare April 8, 2025 10:08
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.

3 participants