javaantdroolsdrools-decisiontables

You're trying to compile a Drools asset without mvel


I have a unit test for my drools project that is running inside my Intellij IDEA environment, but fails in ant build. The error is:

Exception org.drools.base.common.MissingDependencyException: You're trying to compile a Drools asset without mvel. Please add the module org.drools:drools-mvel to your classpath. [in thread "ForkJoinPool-1-worker-3"]

Here is my junit target.

<target name="test" description="Runs all JUnit tests" depends="jar">
    <echo>${toString:test.classpath}</echo>
    <junit haltonfailure="true">
      <classpath refid="test.classpath" />

      <formatter type="brief" usefile="false" />
      <batchtest>
        <fileset dir="${build.classes.dir}">
            <include name="**/*Test.class"/>
            <exclude name="**/RandomBag*.class"/>
        </fileset>
      </batchtest>
    </junit>

    <fail message="test failed" if="test.failure" />
</target>

As you can see, I am echoing the classpath I'm using and it includes drools-mvel library.

After reviewing the stacktrace, it is actually running inside of classes from drols-mvel library.

I googled the error and only found things that did not have drools-mvel in the classpath, which makes me wonder why they posted, but nevermind.

So now I'm stumped and looking for help.

EDIT

So just trying stuff, I figured out that this is probably the line which is generating my error:

    FieldAccessorFactory instance = KieService.load( FieldAccessorFactory.class );

This line of code looks for an implementation of the interface passed. So I looked at drools-mvel jar and found the implementing class it's probably looking for. I then thought I'd see what happens if I ran this line of code outside in my unit test.

I tried it and it worked in both environments, but interestingly generated a bunch of messages in ant outside of intellij

[junit] WARN  Environment variable M2_HOME is not set
[junit] WARN  File 'rules/postponementRules.drl.csv' is in folder 'rules' but declares package 'postponementRules'. It is advised to have a correspondance between package and folder names.
[junit] ERROR Unable to build KieBaseModel:defaultKieBase
[junit] Rule Compilation error : [Rule name='postponePart_18']
[junit]     package com.gs.jxx.bo does not exist
[junit]     package com.gs.jx.request does not exist
[junit]     package com.gs.jxx.request does not exist

Keep in mind, these unit tests run just fine inside of IntelliJ. And I verified that the directory that contains these packages is on the classpath dumped by the echo.

So I dig some and figure out that ant runs it's own class loader AntClassLoader as opposed to the JDK internal one that runs inside of intelliJ.

I don't know what all of this means, but they appear to be pieces of the puzzle.


Solution

  • This was caused by a classpath issue. I had multiple versions of drools on my classpath causing a mismatch.

    After great effort, managed to square away classpath and it is all working.