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

3.1k views Asked by At

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.

1

There are 1 answers

0
r4zzz4k On BEST ANSWER

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.