Greetings! I'm seeking some assistance from peopl...
# community-support
d
Greetings! I'm seeking some assistance from people who have a somewhat deep understanding of the connection between Gradle's version and the Kotlin version, which is used to execute
*.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:
Copy code
pluginManagement {
    includeBuild("./build-src")
    <REST_OF_THE_SETUP>
• The
build-src
project is also multimodule and has the following structure:
Copy code
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
Copy code
// 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?
Gradle 7.5's embedded Kotlin is (compatible with) 1.4, and uppercase() was introduced in Kotlin 1.5
as for
private 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