Robert Jaros
01/26/2023, 12:53 PM> Cannot change attributes of dependency configuration ':generatedByKspKotlinFrontendApiDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':generatedByKspKotlinFrontendImplementationDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':generatedByKspKotlinFrontendCompileOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':generatedByKspKotlinFrontendRuntimeOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':generatedByKspKotlinFrontendIntransitiveDependenciesMetadata' after it has been resolved
Robert Jaros
01/26/2023, 12:55 PMRobert Jaros
01/26/2023, 3:04 PMbootJar
Spring Boot task:
getByName("bootJar", BootJar::class) {
dependsOn("frontendArchive", "backendMainClasses")
classpath = files(
kotlin.targets["backend"].compilations["main"].output.allOutputs +
project.configurations["backendRuntimeClasspath"] +
(project.tasks["frontendArchive"] as Jar).archiveFile
)
}
Robert Jaros
01/26/2023, 3:05 PMgetByName("bootJar", BootJar::class) {
dependsOn("frontendArchive", "backendMainClasses")
classpath = files(
kotlin.targets["backend"].compilations["main"].output.allOutputs,
project.configurations["backendRuntimeClasspath"],
(project.tasks["frontendArchive"] as Jar).archiveFile
)
}
it works the same but the problem is gone.Robert Jaros
01/26/2023, 3:06 PMTing-Yuan Huang
01/26/2023, 5:19 PMRobert Jaros
02/05/2023, 11:29 AMRobert Jaros
02/05/2023, 11:29 AMafterEvaluate {
configurations["jvmRuntimeClasspath"].files
}
at the end of https://github.com/google/ksp/blob/main/examples/multiplatform/workload/build.gradle.ktsRobert Jaros
02/05/2023, 11:30 AMA problem occurred configuring project ':workload'.
> Failed to notify project evaluation listener.
> Cannot change attributes of dependency configuration ':workload:generatedByKspKotlinJsApiDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspKotlinJsImplementationDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspKotlinJsCompileOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspKotlinJsRuntimeOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspKotlinJsIntransitiveDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspTestKotlinJsApiDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspTestKotlinJsImplementationDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspTestKotlinJsCompileOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspTestKotlinJsRuntimeOnlyDependenciesMetadata' after it has been resolved
> Cannot change attributes of dependency configuration ':workload:generatedByKspTestKotlinJsIntransitiveDependenciesMetadata' after it has been resolved
Robert Jaros
02/05/2023, 11:31 AMRobert Jaros
02/05/2023, 11:32 AMRobert Jaros
02/05/2023, 11:35 AMconfigurations["jvmRuntimeClasspath"].files
is a typical way to find jvm dependencies when building "fat jar". I've googled, but couldn't find another working way to do this.Robert Jaros
02/05/2023, 11:37 AMCannot change dependencies of dependency configuration ':implementation' after it has been included in dependency resolution.
Robert Jaros
02/05/2023, 11:45 AMafterEvaluate {
configurations.filter { it.name.startsWith("js") && it.name.endsWith("DependenciesMetadata") }
.forEach {
configurations.remove(it)
}
configurations["jvmRuntimeClasspath"].files
}
I have no idea what it breaks (probably a lot 😉), but my project seems to work fine with this.Robert Jaros
02/05/2023, 11:46 AMRobert Jaros
02/05/2023, 11:46 AMTing-Yuan Huang
02/08/2023, 9:57 PMBig Chungus
02/10/2023, 12:13 PMafterEvaluate {
configurations.filter { it.name.startsWith("generatedByKspKotlinJs") && it.name.endsWith("DependenciesMetadata") }
.forEach {
configurations.remove(it)
}
}
Robert Jaros
02/10/2023, 12:24 PMAnton Lakotka [JB]
03/14/2023, 7:49 AMafterEvaluate
block.
3. changing attributes of a configuration that contribute to jvmRuntimeClasspath through Configuration::extendsFrom
api.
When you changed in your code from:
files(
/*...*/
project.configurations["backendRuntimeClasspath"] +
(project.tasks["frontendArchive"] as Jar).archiveFile
)
to this:
files(
/*...*/
project.configurations["backendRuntimeClasspath"],
(project.tasks["frontendArchive"] as Jar).archiveFile
)
You actually told gradle to resolve this configuration lazily.
And that fixed the issue.
Why it got resolved eagerly before that change?
Because there is no operator fun FileCollection.plus(file: File)
but there is operator fun Iterable<T>.plus(element: T): List<T>
and Configuration
implements FileCollection
which also implements Iterable<File>
. And iterating over Configuration
or FileCollection
triggers its resolution.
So general recommendation is to try to avoid configuration resolution as much as possible. For such thing you can use protection mechanism implemented by Android Gradle Plugin: DependencyResolutionChecks.kt
Nevertheless issue is still valid for Kotlin Gradle Plugin.