Could not open cp_dsl generic class cache for script


import java.util.*

apply(from = resources.text.fromInsecureUri(""))

group = "com.ab.project"

repositories {
    maven {
        isAllowInsecureProtocol = true
        metadataSources {

val remotes: MutableMap<String, MutableMap<String, Any>> = mutableMapOf()
remotes["develop"] = passwordRemote("", 22, "root", "123456")

fun passwordRemote(host: String, port: Int, user: String, password: String): MutableMap<String, Any>{
    return mutableMapOf("host" to host, "port" to port, "user" to user, "password" to password)

extra["remotes"] = remotes

gradle version: 8.2.1
java open sdk: 17.0.8

the gradle project A applys the file (parent.gradle.kts) from two different way:

  1. project A’s build.gradle.kts:
apply(from = resources.text.fromInsecureUri(""))


Build file 'C:\ProjectFamily\pjfamily-config\build.gradle.kts' line: 12

Could not open cp_dsl generic class cache for script 'C:\Users\...\.gradle\.tmp\resource\wrappedInternalText17470423575089172138.txt' (C:\Users\...\.gradle\caches\8.2.1\scripts\46vzq4wslg6f3pgsptuope9an).
> Could not compile script 'C:\Users\...\.gradle\.tmp\resource\wrappedInternalText17470423575089172138.txt'.
   > startup failed:
     script 'C:\Users\...\.gradle\.tmp\resource\wrappedInternalText17470423575089172138.txt': 22: Unexpected input: 'passwordRemote(host: String, port: Int, user: String, password: String):' @ line 22, column 76.
        ser: String, password: String): MutableM

seem it doesn’t support Kotlin?
because I use var variable:String?=XXX show the same error with ?.

  1. project A’s build.gradle.kts:
apply(from = "../parent.gradle.kts")  // download the file and use it locally, it works.

As you see in the error message, the extension of the file is .txt.
So Gradle cannot know which DSL language it is written in.
I guess for backwards compatibility it assumes it is written in Groovy DSL which then of course fails as soon as some Kotlin construct is found that is different from Groovy.

With File extension for TextResource#asFile · Issue #16325 · gradle/gradle · GitHub you could probably mitigate the problem by specifying the file extension.

But actually, using apply from is legacy and highly discouraged anyway.

Better write a convention plugin that you publish to and that you then apply where you want the conventions to be applied to. For implementing it you can for example use precompiled script plugins, which look pretty much like normal build scripts.