【问题标题】:Enabling Executable Rule Models in a drools library在 drools 库中启用可执行规则模型
【发布时间】:2021-09-10 21:20:59
【问题描述】:

我们有一个旧的 drools 库,它一直在升级到 KIE 的更高版本,可执行规则模型引起了我的注意。当我开始迁移时,我的依赖项如下所示:

    <dependencies>
        ...
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mvel</groupId>
            <artifactId>mvel2</artifactId>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>${lombok.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>${kie.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <version>${kie.version}</version>
        </dependency>
    </dependencies>

 <build>
        <plugins>
            ...
            <plugin>
                <groupId>org.kie</groupId>
                <artifactId>kie-maven-plugin</artifactId>
                <version>${kie.version}</version>
                <extensions>true</extensions>
            </plugin>

使用 7.26.0.Final。当我升级到 7.59.0.Final 时,我添加了我应该从文档中添加的编译器依赖项:

        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-model-compiler</artifactId>
            <version>${kie.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
            <version>${kie.version}</version>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
            <version>${kie.version}</version>
        </dependency>

但我的生成模型现在似乎失败了:

[INFO] --- kie-maven-plugin:7.59.0.Final:generateModel (default-generateModel) @ rules ---
[INFO] Using NEW implementation
[INFO] Using NEW implementation
[INFO] Artifact not fetched from maven: org.drools:drools-model-compiler:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.kie:kie-ci:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.apache.commons:commons-collections4:4.4. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.apache.commons:commons-lang3:3.12.0. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.kie:kie-api:7.59.0.Final. To enable the KieScanner you need kie-ci on the classpath
[INFO] Artifact not fetched from maven: org.mvel:mvel2:2.4.12.Final. To enable the KieScanner you need kie-ci on the classpath
WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[WARNING] Found more than one default KieBase: disabling all. KieBases will be accessible only by name
[WARNING] Found more than one default KieSession: disabling all. KieSessions will be accessible only by name
[ERROR] Unable to build KieBaseModel:plan-rules
InvalidExpressionErrorResult: Method equalsAnyIgnoreCase on class org.apache.commons.lang3.StringUtils with arguments [class java.lang.String, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method intersectionsStartsWith on class com.accolade.clinical.utils.RuleUtils with arguments [interface java.util.List, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing
... (A lot more errors of this nature)

为什么即使我已经配置了 maven CI 和插件,它也不会获取依赖项?我在文档中遗漏了什么吗?

编辑:

根据第一个答案:

我尝试将上面列出的 3 个依赖项替换为

    <dependency>
        <groupId>org.drools</groupId>
        <artifactId>drools-engine</artifactId>
        <version>${kie.version}</version>
    </dependency>

但不幸的是,kie 不想在这种情况下使用新的生成模型方法:

[INFO] --- kie-maven-plugin:7.59.0.Final:generateModel (default-generateModel) @ rules ---
[WARNING] You're trying to build rule assets in a project from an executable rule model, but you did not provide the required dependency on the project classpath.
To enable executable rule models for your project, add the `drools-model-compiler` dependency in the `pom.xml` file of your project.

[INFO] 
[INFO] --- kie-maven-plugin:7.59.0.Final:generateDMNModel (default-generateDMNModel) @ rules ---
[INFO] 
[INFO] --- kie-maven-plugin:7.59.0.Final:generatePMMLModel (default-generatePMMLModel) @ rules ---
[WARNING] Skipping `generatePMMLModel` because you did not provide the required dependency on the project classpath.
To enable it for your project, add the `drools-model-compiler` dependency in the `pom.xml` file of your project.

[INFO] 
[INFO] --- kie-maven-plugin:7.59.0.Final:generateANC (default-generateANC) @ rules ---
[INFO] 
[INFO] --- kie-maven-plugin:7.59.0.Final:build (default-build) @ rules ---

这是mvn dependency:tree的输出:

[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------< com.mycompany:rules >---------------------
[INFO] Building Rules 5.0.0-SNAPSHOT
[INFO] --------------------------------[ kjar ]--------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ rules ---
[INFO] com.mycompany:rules:kjar:5.0.0-SNAPSHOT
[INFO] +- com.mycompany.acp.utilities:model-utilities:jar:7.1.0:compile
[INFO] |  +- com.mycompany.acp.fhir:common-fhir:jar:8.2.0:compile
[INFO] |  |  +- io.swagger.core.v3:swagger-annotations:jar:2.1.10:compile
[INFO] |  |  +- io.swagger:swagger-annotations:jar:1.6.2:compile
[INFO] |  |  +- org.reflections:reflections:jar:0.9.12:compile
[INFO] |  |  |  \- org.javassist:javassist:jar:3.26.0-GA:compile
[INFO] |  |  +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] |  |  |  \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] |  |  |  +- commons-logging:commons-logging:jar:1.2:compile
[INFO] |  |  |  \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  |  \- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] |  +- com.github.java-json-tools:json-patch:jar:1.13:compile
[INFO] |  +- com.github.java-json-tools:msg-simple:jar:1.2:compile
[INFO] |  |  \- com.github.java-json-tools:btf:jar:1.3:compile
[INFO] |  +- com.github.java-json-tools:jackson-coreutils:jar:2.0:compile
[INFO] |  +- com.contentful.java:java-sdk:jar:10.4.5:compile
[INFO] |  |  +- com.squareup.retrofit2:retrofit:jar:2.5.0:compile
[INFO] |  |  +- com.squareup.retrofit2:adapter-rxjava2:jar:2.5.0:compile
[INFO] |  |  +- com.squareup.retrofit2:converter-gson:jar:2.5.0:compile
[INFO] |  |  +- io.reactivex.rxjava2:rxjava:jar:2.2.6:compile
[INFO] |  |  |  \- org.reactivestreams:reactive-streams:jar:1.0.2:compile
[INFO] |  |  +- com.squareup.okhttp3:okhttp:jar:3.12.12:compile
[INFO] |  |  |  \- com.squareup.okio:okio:jar:1.15.0:compile
[INFO] |  |  +- com.google.code.gson:gson:jar:2.8.5:compile
[INFO] |  |  \- com.github.tony19:named-regexp:jar:0.2.5:compile
[INFO] |  +- com.mycompany.acp.resources:singularity-models:jar:6.1.0:compile
[INFO] |  |  +- com.mycompany.acp-common-eventbus:models:jar:5.0.3:compile
[INFO] |  |  |  \- com.amazonaws:aws-java-sdk-sns:jar:1.11.625:compile
[INFO] |  |  |     \- com.amazonaws:aws-java-sdk-sqs:jar:1.11.625:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-dynamodb:jar:1.12.18:compile
[INFO] |  |  |  +- com.amazonaws:aws-java-sdk-s3:jar:1.12.18:compile
[INFO] |  |  |  |  \- com.amazonaws:aws-java-sdk-kms:jar:1.12.18:compile
[INFO] |  |  |  +- com.amazonaws:aws-java-sdk-core:jar:1.12.18:compile
[INFO] |  |  |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] |  |  |  |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.13:compile
[INFO] |  |  |  |  +- software.amazon.ion:ion-java:jar:1.0.2:compile
[INFO] |  |  |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-cbor:jar:2.12.3:compile
[INFO] |  |  |  |  \- joda-time:joda-time:jar:2.8.1:compile
[INFO] |  |  |  \- com.amazonaws:jmespath-java:jar:1.12.18:compile
[INFO] |  |  +- com.amazonaws:aws-java-sdk-sts:jar:1.12.18:compile
[INFO] |  |  \- com.mycompany.acp.fhir:common-utilities:jar:8.2.0:compile
[INFO] |  |     \- org.springframework:spring-web:jar:5.3.8:compile
[INFO] |  |        +- org.springframework:spring-beans:jar:5.3.8:compile
[INFO] |  |        \- org.springframework:spring-core:jar:5.3.8:compile
[INFO] |  |           \- org.springframework:spring-jcl:jar:5.3.8:compile
[INFO] |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.12.4:compile
[INFO] |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.4:compile
[INFO] |     \- com.fasterxml.jackson.core:jackson-core:jar:2.12.4:compile
[INFO] +- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] +- commons-io:commons-io:jar:2.11.0:compile
[INFO] +- org.mvel:mvel2:jar:2.4.12.Final:compile
[INFO] +- org.slf4j:slf4j-api:jar:2.0.0-alpha5:provided
[INFO] +- org.projectlombok:lombok:jar:1.18.20:provided
[INFO] +- org.drools:drools-engine:jar:7.59.0.Final:compile
[INFO] |  +- org.kie:kie-api:jar:7.59.0.Final:compile
[INFO] |  |  \- org.kie.soup:kie-soup-maven-support:jar:7.59.0.Final:compile
[INFO] |  +- org.kie:kie-internal:jar:7.59.0.Final:compile
[INFO] |  +- org.drools:drools-core:jar:7.59.0.Final:compile
[INFO] |  |  +- org.kie.soup:kie-soup-xstream:jar:7.59.0.Final:compile
[INFO] |  |  +- org.drools:drools-core-reflective:jar:7.59.0.Final:compile
[INFO] |  |  +- org.drools:drools-core-dynamic:jar:7.59.0.Final:runtime
[INFO] |  |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] |  +- org.drools:drools-compiler:jar:7.59.0.Final:compile
[INFO] |  |  +- org.kie:kie-memory-compiler:jar:7.59.0.Final:compile
[INFO] |  |  +- org.drools:drools-ecj:jar:7.59.0.Final:compile
[INFO] |  |  +- org.antlr:antlr-runtime:jar:3.5.2:compile
[INFO] |  |  \- com.thoughtworks.xstream:xstream:jar:1.4.17:compile
[INFO] |  |     \- io.github.x-stream:mxparser:jar:1.2.1:compile
[INFO] |  |        \- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] |  \- org.drools:drools-model-compiler:jar:7.59.0.Final:compile
[INFO] |     +- org.drools:drools-canonical-model:jar:7.59.0.Final:compile
[INFO] |     +- com.github.javaparser:javaparser-core:jar:3.13.10:compile
[INFO] |     +- org.drools:drools-mvel-parser:jar:7.59.0.Final:compile
[INFO] |     \- org.drools:drools-mvel-compiler:jar:7.59.0.Final:compile
[INFO] +- xerces:xercesImpl:jar:2.12.1:test
[INFO] |  \- xml-apis:xml-apis:jar:1.4.01:test
[INFO] +- com.google.guava:guava:jar:30.1.1-jre:test
[INFO] |  +- com.google.guava:failureaccess:jar:1.0.1:test
[INFO] |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:test
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  +- org.checkerframework:checker-qual:jar:3.8.0:test
[INFO] |  +- com.google.errorprone:error_prone_annotations:jar:2.5.1:test
[INFO] |  \- com.google.j2objc:j2objc-annotations:jar:1.3:test
[INFO] +- org.junit.jupiter:junit-jupiter-api:jar:5.7.2:test
[INFO] |  +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] |  +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] |  \- org.junit.platform:junit-platform-commons:jar:1.7.2:test
[INFO] +- org.junit.jupiter:junit-jupiter-engine:jar:5.7.2:test
[INFO] |  \- org.junit.platform:junit-platform-engine:jar:1.7.2:test
[INFO] \- org.junit.jupiter:junit-jupiter-params:jar:5.7.2:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.439 s
[INFO] Finished at: 2021-09-19T23:53:58-07:00
[INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 尝试分析你的依赖关系。在我看来,您的类路径中可能存在冲突。
  • 说得好,我会这样做的。
  • @EstebanAliverti 我尝试分析依赖关系,虽然番石榴内部库中存在一些冲突,但 common-collections4 或 common-lang3 之类的东西没有,而且这些也没有在 generateModel 步骤中加载.

标签: java drools rule-engine kie


【解决方案1】:

您可以尝试使用these 新的包装模块吗?他们应该可以解决您的问题

" 这个问题主要是因为用户在他们的依赖模块中,比如 drools-core 和 drools-compiler,实际上只不过是“内部实现细节”。为避免将来出现类似问题,在极有可能引入其他模块以将引擎拆分为更细粒度的子模块并取消可选功能的情况下,我们创建了以下 2 个新的包装器模块,以涵盖 2 个不同的主要使用场景:

drools-engine 聚合 drools-coredrools-compilerdrools-model-compiler

drools-engine-classic 聚合 drools-coredrools-compilerdrools-mvel "

如果要使用可执行模型,请使用 drools-engine

编辑:

如果你看到这个错误信息,依赖是正确的

InvalidExpressionErrorResult: Method equalsAnyIgnoreCase on class org.apache.commons.lang3.StringUtils with arguments [class java.lang.String, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method intersectionsStartsWith on class com.accolade.clinical.utils.RuleUtils with arguments [interface java.util.List, class java.lang.Object] is missing
InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing

这意味着可执行模型正在编译,但它在您的某些规则上失败。我们需要一个复制器来看看现在发生了什么。例如行

InvalidExpressionErrorResult: Method size on class java.lang.Object with arguments [] is missing

看起来很奇怪,因为 Object 没有 size() 方法。

请在 issues.redhat.com 上传您的混淆规则提交错误,以便我们进一步调查。

【讨论】:

  • 我试图用聚合 jar 替换依赖项,但不幸的是,这禁用了新的生成模型,并且似乎破坏了旧的 drools 编译。编辑下的原始问题中的详细信息。
  • @RMSD 请同时发布mvn dependency:tree 的输出,谢谢
  • 我已经在原始问题中发布了依赖树的输出。
猜你喜欢
  • 2019-04-08
  • 1970-01-01
  • 1970-01-01
  • 2015-06-11
  • 2022-11-30
  • 2017-03-24
  • 2019-06-25
  • 2011-05-22
  • 2012-06-05
相关资源
最近更新 更多