Search code examples
excelmavencompilationspreadsheetdrools

Drools decision tables precompilation using Maven


According to the drools 6.3 documentation, section 4.2.2.3 :

The KIE plugin for Maven ensures that artifact resources are validated and pre-compiled, it is recommended that this is used at all times. To use the plugin simply add it to the build section of the Maven pom.xml

Consequently, my pom.xml is :

<dependencies>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-compiler</artifactId>
        <version>6.3.0.Final-redhat-9</version>
    </dependency>
    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-decisiontables</artifactId>
        <version>6.3.0.Final-redhat-9</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.kie</groupId>
            <artifactId>kie-maven-plugin</artifactId>
            <version>6.3.0.Final-redhat-9</version>
            <extensions>true</extensions>
        </plugin>
    </plugins>
</build>

I placed my decision table file, let's call it rules.xls, in the src/main/resources/my/company/package/. The one and only other file in my Maven project is the kmodule.xml file, which is in src/main/resources/META-INF/ and contains the minimal code :

<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule"/>

Because I removed all the other dependencies (including the one that contains the Java objects used in the decision table), I was expecting drools to launch an error message of type cannot find symbol.

But when I try to clean install the project using Maven, the compilation succeed, a JAR file is created and it does contain the kmodule.xml and rules.xls files at the exact location where I placed them. No additional file generated during compilation, no error, no warning, nothing. Just a plain JAR with my files, a MANIFEST.MF file and a maven directory under META-INF.

In the maven trace, here are the plugins activated (in that order) :

[INFO] --- maven-clean-plugin:2.4.1:clean
[INFO] --- maven-resources-plugin:2.5:resources
[INFO] --- maven-compiler-plugin:2.3.2:compile
[INFO] --- maven-resources-plugin:2.5:testResources
[INFO] --- maven-compiler-plugin:2.3.2:testCompile
[INFO] --- maven-surefire-plugin:2.10:test
[INFO] --- maven-jar-plugin:2.3.2:jar
[INFO] --- maven-install-plugin:2.3.1:install

Nothing about the kie plugin. Any hint to activate the rules compilation at build time ?


Solution

  • I finally did find a way to activate the plugin. I added this to my pom.xml :

    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.kie</groupId>
          <artifactId>kie-maven-plugin</artifactId>
          <version>6.3.0.Final-redhat-9</version>
          <extensions>true</extensions>
          <executions>
            <execution>
              <id>brms-rules-compilation</id>
              <phase>generate-resources</phase>
              <goals>
                <goal>build</goal>
              </goals>
              <inherited>false</inherited>
              <configuration>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
    

    And now get a Drools compilation trace including :

    [INFO] --- kie-maven-plugin:6.3.0.Final-redhat-9:build
    [main] INFO org.drools.compiler.kie.builder.impl.KieRepositoryImpl - Adding KieModule from resource: FileResource[...]
    

    I'm no Maven guru, this solution may not be the best (I even do not entirely understand what I wrote as a Maven perspective), so I would be glad to get an easier one.