Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 743
Manu D. Avatar asked Sep 17 '20 21:09

Manu D.


People also ask

Does indentation matter in Kotlin?

In Kotlin coding conventions, it's recommended to use a single indent in cases where the long continuation indent has been forced before. In practice, quite a bit of code is affected, so this can be considered a major code style update.

Does Gradle support Kotlin?

Gradle is a build system that is very commonly used in the Java, Android, and other ecosystems. It is the default choice for Kotlin/Native and Multiplatform when it comes to build systems.


1 Answers

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.

like image 66
r4zzz4k Avatar answered Oct 29 '22 02:10

r4zzz4k