How to properly add dependency to another plugin: "TestProxy cannot be cast to TestProxy"


My plugin needs to depend on some classes (like TestProxy) from com.intellij.execution.junit2. Which is another plugin.
So I add /Applications/IntelliJ IDEA 13 as a dependency for my own module (in File -> Project Structure -> ...)

However, for the following piece of code:

public void testSuiteFinished(AbstractTestProxy root) {

     TestProxy junitTest = (TestProxy) root;


I get the following exception (which you don't quite see everyday):

java.lang.ClassCastException: com.intellij.execution.junit2.TestProxy cannot be cast to com.intellij.execution.junit2.TestProxy

This is because the class files are loaded by different class loaders. If I print the class loaders I get:

my TestProxy classloader: PluginClassLoader[, 0.1]

IDEA's TestProxy classloader: PluginClassLoader[JUnit, 1.0]

I also tried adding <depends>JUnit</depends> to my plugin.xml but the same exception gets thrown.

So my question is, how can I depend on a plugin that IDEA also uses? As in depend on the same instance of the plugin.

Comment actions Permalink

You must add any plugin dependencies not to your module, but to the IntelliJ Platform SDK you're using.
Additionally your plugin must add corresponding <depends> tags to determine runtime dependencies.

Comment actions Permalink

I moved the static dependency from the module into the SDK and it worked. Thanks.

Comment actions Permalink

Change the scope of the dependency in the module dependencies config to 'provided' so it correctly gets loaded by the launched instance of IDEA rather than the system classpath.


Please sign in to leave a comment.