Loading groovy classes with conflicting names
<p>I use <code>GroovyScriptEngine</code> inside my Java application to load code dynamically from different sources. Let's say I have two folders <code>sources_A\</code> and <code>sources_B\</code>.</p>

<pre><code>GroovyScriptEngine engine = new GroovyScriptEngine(new String[]{
    "sources_A", "sources_B"
});
</code></pre>

<p>Within each folder I have Groovy packages and classes that I wish to instantiate arbitrarily at runtime. </p>

<p><strong>Problem:</strong> Some of these classes have the same (full) name in both folders.</p>

<p>So there is an ambiguity when I run:</p>

<pre><code>engine.loadScriptByName("some.package.SomeClass").newInstance()
</code></pre>

<p>Of course, I could create two different engines:</p>

<pre><code>GroovyScriptEngine engine_A = new GroovyScriptEngine(new String[]{"sources_A"});
GroovyScriptEngine engine_B = new GroovyScriptEngine(new String[]{"sources_B"});
</code></pre>

<p>But then I run into issues when two objects instantiated from these two different engines have to interact with each other:</p>

<pre><code>object_from_A.someMethod(object_from_B);
</code></pre>

<blockquote>
  <p>Error: argument type mismatch at line ** in method foo in file bar.groovy</p>
</blockquote>

<p>(Needless to say that there is no type mismatch: the object has the right type but is not recognized due to the different engine)</p>

<p><strong>In short</strong>, do you have a solution to either:</p>

<ul>
<li>The one-engine solution with some way to disambiguate which source folder is used?</li>
<li>The two-engine solution with some way to have objects from the two different engines to work together?</li>
</ul>