JetBrains / intellij-platform-gradle-plugin

Gradle plugin for building plugins for IntelliJ-based IDEs
https://plugins.jetbrains.com/docs/intellij/gradle-prerequisites.html
Apache License 2.0
1.42k stars 270 forks source link

Classes from V2 "modules" are accessible on the compile classpath (but inaccessible at runtime by default) #1761

Closed gharrma closed 1 day ago

gharrma commented 1 week ago

What happened?

Plugins can easily be hit by ClassNotFoundException at runtime if they access classes from V2 "modules".

I've created a minimal repro scenario as a patch on top of the intellij-platform-plugin-template: https://github.com/gharrma/intellij-plugin-repro-module-dependency-violation/commit/8291e98b2e7808301cea3af22826101abc04b4f8

Observed behavior:

Expected behavior:


Note, I believe commit https://github.com/JetBrains/intellij-community/commit/6fb57f5b2d5346c7a622cde47e6d2d6c11acdf2f in IntelliJ 2024.2 is what placed V2 modules into a separate classloader at runtime (thus requiring the explicit dependency declaration in plugin.xml).

Let me know if I should file a separate issue for intellij-plugin-verifier, given that the verifier should be reporting these dependency violations too. (Should I file this issue on YouTrack?)

Relevant log output or stack trace

java.lang.NoClassDefFoundError: com/intellij/smartUpdate/VcsUpdateStep
    at org.jetbrains.plugins.template.listeners.MyApplicationActivationListener.applicationActivated(MyApplicationActivationListener.kt:14)
    ...
Caused by: java.lang.ClassNotFoundException: com.intellij.smartUpdate.VcsUpdateStep PluginClassLoader(plugin=PluginDescriptor(name=IntelliJ Platform Plugin Template, id=org.jetbrains.plugins.template, descriptorPath=plugin.xml, path=~/dev/misc/repro-module-dependency-violation/build/idea-sandbox/IC-2024.2/plugins/IntelliJ Platform Plugin Template, version=2.0.1, package=null, isBundled=false), packagePrefix=null, state=active, parents=, )
    at com.intellij.ide.plugins.cl.PluginClassLoader.loadClass(PluginClassLoader.kt:157)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
    ...

Steps to reproduce

[See repro steps in the main description.]

Gradle IntelliJ Plugin version

2.0.1

Gradle version

8.9

Operating System

macOS

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

No response

gharrma commented 1 week ago

It appears this might be related to the to-do comment added in commit https://github.com/JetBrains/intellij-platform-gradle-plugin/commit/abc9ee737681269598a80af50850df91a44cdb31.

hsz commented 1 day ago

Fixed by removing!