Den Drobiazko
10/22/2024, 2:56 PM*.gradle.kts scripts.
My environment is as such:
• Gradle wrapper is used (distributionUrl=https\:<//services.gradle.org/distributions/gradle-7.5-bin.zip>)
• Gradle Kotlin DSL is used
• Multimodule Android project
• Included builds are used: settings.gradle.kts file has this code written:
pluginManagement {
includeBuild("./build-src")
<REST_OF_THE_SETUP>
• The build-src project is also multimodule and has the following structure:
build-src/
|
|-- module1 folder
| |-- src folder
| \-- build.gradle.kts file
|
|-- module2 folder
| |-- src folder
| \-- build.gradle.kts file
|
|-- module3 folder
| |-- src folder
| \-- build.gradle.kts file
|
|-- build.gradle.kts file // <<<<<-------- attention here, please! Read below...
\-- settings.gradle.kts file
• root build.gradle.kts file in included build project has nothing but some code like
// first line of build-src/build.gradle.kts file
import org.gradle.api.Project
// define fun to run below:
private fun myCodeToRunDuringGradleSyncWhatever(project: Project) {
// here goes some code, that does stuff to properly set up our big project - it's implementation does not matter
}
// run this function:
myCodeToRunDuringGradleSyncWhatever(getProject())
With this setup in mind, I can now describe the issue:
running the ./gradlew command in root project dir gives me a very strange error - build-src/build.gradle.kts:5:1: Modifier 'private' is not applicable to 'local function'
pointing to me the definition of my myCodeToRunDuringGradleSyncWhatever fun.
NOTE: a significant detail is that if I change the Gradle wrapper's version to use to 8.5 - the problem is gone. But now I need to create a branch with a backport to run under Gradle 7.5 and this is a problem.
Let's say I remove all those private modifiers from all my `fun`'s in this file.
It then starts to give me even more strange compilation issues, pointing to various Kotlin standard methods in my myCodeToRunDuringGradleSyncWhatever fun (like String.uppercase()).
I am sure I'm missing something in the environment setup here, but what?ephemient
10/22/2024, 3:06 PMephemient
10/22/2024, 3:07 PMephemient
10/22/2024, 3:15 PMprivate fun etc., Kotlin scripts are compiled a bit differently than regular Kotlin files, they're sort of wrapped in a class and function, which makes some features you would expect at the top-level of a Kotlin file unavailable, such as https://youtrack.jetbrains.com/issue/KT-20110