Hm.. this problem is really annoying and there is no workaround. Now I even get a weirder error:
The org.jacorb.idl stuff AND the java_cup.runtime are both in the same jar file! This might be a bug
in Jacorb, but when run from the projects themselves, everything goes OK.
It doesn't matter if I specify the dependencies in a dependencyManagement in the root pom,
or in the project's declaring the plugin themselves.
I even tried the idlj-maven-plugin in mojo's sandbox. It's used twice in the entire reactor tree.
The plugin itself does not define the jacorb dependency, so I had to define it. I tried <build><extensions>,
root pom's pluginManagement, and both pom's. Since this is the exact same plugin with the exact same
deps and configuration, it should work. Unfortunately it doesn't.
Now, about a solution.
M2 currently disposes the PlexusRealm for the plugin after each execution. However,
the classloader is set to the mojoDescriptor.getPluginDescriptor().getClassRealm().getClassLoader().
This classloader/classRealm is NOT disposed of. I'm not sure why the PlexusRealm isn't equal to the
pluginDescriptor's classRealm. There should be one access point to manage a plugin's execution environment.
If this were fixed, John Casey's comment above about the ArtifactHandlerManager comes into play.
A suggestion: We could leave the plugin's declared dependencies in the same classloader as the plugin's artifact.
We could add a NEW classloader containing the project's <dependencies> for that plugin, and hook that into
the plugin's classloader as a child. After execution, we unhook it (perhaps a child PlexusRealm?)
I would really like to get this fixed in 2.0.5. My previous workaround (specifying the filename of the dependency
in an ant script's TaskDef tag) doesn't work anymore since 2.0.4.