WellD Kogito KJAR Maven Plugin

A Maven plugin to use KJARs in Kogito

License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

ch.welld.kie
ArtifactId

ArtifactId

welld-kogito-kjar-maven-plugin
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

WellD Kogito KJAR Maven Plugin
A Maven plugin to use KJARs in Kogito
Project URL

Project URL

https://github.com/welldsagl/drools-gdst-to-drl
Project Organization

Project Organization

com.github.welldsagl
Source Code Management

Source Code Management

https://github.com/welldsagl/drools-gdst-to-drl

Download welld-kogito-kjar-maven-plugin

How to add to project

<plugin>
    <groupId>ch.welld.kie</groupId>
    <artifactId>welld-kogito-kjar-maven-plugin</artifactId>
    <version>1.2.0</version>
</plugin>

Dependencies

compile (2)

Group / Artifact Type Version
org.drools : drools-workbench-models-guided-dtable jar 7.30.0.Final
org.drools : drools-workbench-models-guided-template jar 7.30.0.Final

provided (4)

Group / Artifact Type Version
org.apache.maven : maven-plugin-api jar 3.3.9
org.apache.maven : maven-core jar 3.3.9
org.apache.maven : maven-artifact jar 3.3.9
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.6.0

test (3)

Group / Artifact Type Version
org.apache.maven : maven-compat jar 3.3.9
junit : junit jar 4.12
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0

Project Modules

There are no modules declared in this project.

Codecov GitHub Workflow Status

WellD Kogito KJAR Maven plugin

This plugin can be used to copy and, if necessary, convert the files composing the Drools knowledge.

Why does this exist?

At the time of writing, Kogito does not support loading knowledge from a kjar dependency. Furthermore, it is unable of understanding Guided Decision Table (.gdst) files or Guided Template Rules (.template) files. This plugin provides a workaround by copying files to a Kogito resources directory at compile time, and converting all .gdst and .template files to .drl files.

How it works

The plugin looks into the chosen input directory (parameter inputDirectory) for Drools knowledge files.

  • For each .gdst or .template file the plugin creates a corresponding drl translation in the chosen output directory (outputDirectory).
  • .drl files are simply copied into the output directory.

Folder structure is preserved after the copy, for instance if the input directory is source and has the following structure

   myproject/
   └── source/
       ├── dogs.gdst
       ├── cats.drl
       └── others/
           └── birds.gdst

the output directory target will preserve the relative position of every file after executing the plugin

    myproject/
    └── target/
        ├── dogs.drl
        ├── cats.drl
        └── others/
            └── birds.drl

The gdst-to-drl conversion leverages the Drools Java API provided by the drools-workbench-models-guided-dtable library.

Basic usage

In order to activate the knowledge conversion and copy, you have to add the plugin to the build/plugins section of your project's pom.xml.

<plugin>
    <groupId>ch.welld.kie</groupId>
    <artifactId>welld-kogito-kjar-maven-plugin</artifactId>
    <version>1.1.0-SNAPSHOT</version>
    <executions>
      <execution>
        <id>knowledgeconversion</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>convert-knowledge</goal>
        </goals>
        <configuration>
          <inputDirectory>./drools</inputDirectory>
          <outputDirectory>./src/main/resources</outputDirectory>
          <overwriteFiles>true</overwriteFiles>
        </configuration>
      </execution>
    </executions>
</plugin>

Parameters

The plugin supports the following parameters:

Parameter Type Default Description
inputDirectory String - The directory where drools knowledge files are read from. REQUIRED parameter.
outputDirectory String - The directory where drools knowledge files are saved. REQUIRED parameter.
overwriteFiles boolean false If true existing files in the output directory will be overridden by the new ones, otherwise old ones will be preserved.

Complete usage example

  1. Configure maven-dependency-plugin to extract knowledge files from a dependency to a temporary directory;
  2. Configure welld-drools-maven-plugin to copy and convert files from the temporary directory;
  3. Use maven-clean-plugin to cleanup the copied files in the clean phase.

The temporary directory is not deleted, so you may want to add it (together with the output directory) to your .gitignore.

<build>
    <plugins>
        <plugin>
            <artifactId>maven-clean-plugin</artifactId>
            <version>3.1.0</version>
            <configuration>
              <filesets>
                <fileset><directory>drools</directory></fileset>
                <fileset><directory>src/main/resources/drools</directory></fileset>
              </filesets>
            </configuration>
          </plugin>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.1.1</version>
            <executions>
              <execution>
                <id>unpack</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>ch.welld.schindler.fixture</groupId>
                      <artifactId>droolsknowledge</artifactId>
                      <outputDirectory>./drools</outputDirectory>
                      <includes>**/*.drl,**/*.gdst,,**/*.template</includes>
                    </artifactItem>
                  </artifactItems>
                  <overWriteReleases>true</overWriteReleases>
                </configuration>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>ch.welld.kie</groupId>
            <artifactId>welld-kogito-kjar-maven-plugin</artifactId>
            <version>1.1.0-SNAPSHOT</version>
            <executions>
              <execution>
                <id>knowledge-conversion</id>
                <phase>generate-resources</phase>
                <goals>
                  <goal>convert-knowledge</goal>
                </goals>
                <configuration>
                  <inputDirectory>./drools</inputDirectory>
                  <outputDirectory>./src/main/resources/drools</outputDirectory>
                  <overwriteFiles>true</overwriteFiles>
                </configuration>
              </execution>
            </executions>
          </plugin>
    </plugins>
</build>

Known limitations

WARNING: Be careful with input files with same name but different extension because only one of them will be saved into the output directory. We plan to fix this problem eventually.

ch.welld.kie

wellD

Versions

Version
1.2.0
1.1.0