Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException with ShimMaanagerService on multi module with org.jetbrains.intellij.platform 2.0.0-beta8 #1680

Open
bric3 opened this issue Jul 4, 2024 · 0 comments
Assignees
Labels
Milestone

Comments

@bric3
Copy link
Contributor

bric3 commented Jul 4, 2024

What happened?

The ClassCastException on ShimManagerService happens when two modules (possibly dependant to one another), use the following dependencies declaration

classDiagram
    components <|-- components-demo

    direction LR
Loading
repositories {
    intellijPlatform {
        defaultRepositories() // CCE raised in second module
        jetbrainsRuntime()
    }
}

Looking at the code I noticed this in IntelliJPlatformRepositoriesHelper (called by createJetBrainsCdnArtifactsRepository, note this method is removed in 55eaa4d, but the field remains)

    private val shimManager = gradle.sharedServices.registerIfAbsent(Services.SHIM_MANAGER, ShimManagerService::class) {
        parameters.port = 7348 // TODO: read from Gradle properties
    }

The exception indicates the class is incorrect, indeed module have different classloaders

  • components module: InstrumentingVisitableURLClassLoader(ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:]:buildSrc[:]:root-project[:]:project-components(export)})

  • components-demo-plugin module: InstrumentingVisitableURLClassLoader(ClassLoaderScopeIdentifier.Id{coreAndPlugins:settings[:]:buildSrc[:]:root-project[:]:project-components-demo-plugin(export)})

So shared services in multi module and with configuration cache appear to be subject to CCE. See

  1. Build services can only be registered if the set of applied plugins is the same on all projects gradle/gradle#17559
  2. Crash when manually creating BuildService in two modules gradle/gradle#18821

Workaround: Declare the plugin on the root project without applying it

plugins {
    alias(libs.plugins.detekt)
    alias(libs.plugins.spotless)
    alias(libs.plugins.jetbrains.intellijPlatform) apply false
}

Relevant log output or stack trace

Build file '/Users/brice.dutheil/opensource/intellij-platform-swing-components/components-demo-plugin/build.gradle.kts' line: 30

class org.jetbrains.intellij.platform.gradle.services.ShimManagerService$Inject cannot be cast to class org.jetbrains.intellij.platform.gradle.services.ShimManagerService (org.jetbrains.intellij.platform.gradle.services.ShimManagerService$Inject is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @76b77cf8; org.jetbrains.intellij.platform.gradle.services.ShimManagerService is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @36699c9e)

* Try:
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org/.

* Exception is:
java.lang.ClassCastException: class org.jetbrains.intellij.platform.gradle.services.ShimManagerService$Inject cannot be cast to class org.jetbrains.intellij.platform.gradle.services.ShimManagerService (org.jetbrains.intellij.platform.gradle.services.ShimManagerService$Inject is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @76b77cf8; org.jetbrains.intellij.platform.gradle.services.ShimManagerService is in unnamed module of loader org.gradle.internal.classloader.VisitableURLClassLoader$InstrumentingVisitableURLClassLoader @36699c9e)
	at org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformRepositoriesHelper.createJetBrainsCdnArtifactsRepository$IntelliJ_Platform_Gradle_Plugin(IntelliJPlatformRepositoriesHelper.kt:157)
	at org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformRepositoriesExtension.jetBrainsCdn(IntelliJPlatformRepositoriesExtension.kt:195)
	at org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformRepositoriesExtension.jetBrainsCdn$default(IntelliJPlatformRepositoriesExtension.kt:195)
	at org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformRepositoriesExtension.defaultRepositories(IntelliJPlatformRepositoriesExtension.kt:211)
	at Build_gradle$1$1.execute(build.gradle.kts:30)
	at Build_gradle$1$1.execute(build.gradle.kts:29)
	at org.gradle.internal.extensibility.ExtensionsStorage$ExtensionHolder.configure(ExtensionsStorage.java:177)
	at org.gradle.internal.extensibility.ExtensionsStorage.configureExtension(ExtensionsStorage.java:64)
	at org.gradle.internal.extensibility.DefaultConvention.configure(DefaultConvention.java:207)
	at org.gradle.kotlin.dsl.Accessors71yjfozemurtyc5m7du5ty1x0Kt.intellijPlatform(Unknown Source)
	at Build_gradle$1.invoke(build.gradle.kts:29)
	at Build_gradle$1.invoke(build.gradle.kts:26)
	at org.gradle.kotlin.dsl.ProjectExtensionsKt.repositories(ProjectExtensions.kt:217)
	at Build_gradle.<init>(build.gradle.kts:26)
	...

Steps to reproduce

I'm not quite sure what caused this at this time, this was happening on

https://github.com/bric3/intellij-platform-swing-components/tree/4e57ab2efcab28e739a3bd8f6874e17b2fe1c087

Gradle IntelliJ Plugin version

2.0.0-beta8

Gradle version

8.8

Operating System

macOS

Link to build, i.e. failing GitHub Action job

No response

@bric3 bric3 added the bug label Jul 4, 2024
bric3 added a commit to bric3/intellij-platform-swing-components that referenced this issue Jul 4, 2024
@YannCebron YannCebron added this to the 2.0 milestone Jul 4, 2024
bric3 added a commit to bric3/intellij-platform-swing-components that referenced this issue Jul 4, 2024
@hsz hsz modified the milestones: 2.0, 2.x Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants