How does kotlin-gradle-plugin use 'kotlin.code.style' property?
Asked Answered
V

1

18

The official Kotlin documentation states:

Add kotlin.code.style=official property to the gradle.properties file at the project root.

I'm trying to understand how kotlin-gradle-plugin handles this property.

Which gradle task uses it?
When running gradle build, I don't see my code being reformatted, even if I format my code badly on purpose.

I went through the Github source code of the plugin but couldn't properly get to understand it.

Thanks for your help.

Vanhomrigh answered 17/9, 2020 at 21:17 Comment(1)
Gradle won't reformat your code. Instead, IntelliJ will format your code, if configured so. As this configuration may not be put into version control, there is an option to apply this configuration using gradle.properties, as this file will be in version control anyhow.Gibber
W
15

Kotlin Gradle plugin doesn't use this property, as it's not responsible for reformatting the code. Instead, this property is used by Gradle importer of Kotlin plugin for IntelliJ IDEA.

This facade provides access to Gradle properties defined for the project: https://github.com/JetBrains/kotlin/blob/v1.4.10/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/GradlePropertiesFileFacade.kt It checks local.properties first in case user wants to override this value in the local configuration (this file is usually added to .gitignore for VCS to skip it during it's operations), then in usual gradle.properties. Then the property gets consumed to configure the project here: https://github.com/JetBrains/kotlin/blob/v1.4.10/idea/idea-gradle/src/org/jetbrains/kotlin/idea/configuration/KotlinGradleSourceSetDataService.kt#L158-L159

Same thing goes for Maven-based projects. These are the only two places the property is used throughout Kotlin repository apart from tests right now.

Wessels answered 17/9, 2020 at 22:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.