kie-maven-plugin无法结合Java和DRL事实来生成模型

时间:2019-04-26 13:15:34

标签: drools

我正在尝试使用kie-maven-plugin生成一个完全编译的kmodule。当所有事实都在DRL中定义时,它可以工作,但是当某些事实被定义为Java POJO时,它会失败。

在同一项目中:

Java事实(src \ main \ java \ org \ example \ FactA.java):

package org.example;

public class FactA {

    private String propA;

    public FactA() { }

    public FactA(String propA) {
        this.propA = propA;
    }

    public String getPropA() {
        return propA;
    }

    public void setPropA(String propA) {
        this.propA = propA;
    }
}

DRL事实(src \ main \ resources \ org \ example \ decB.drl):

package org.example

import org.example.FactA

declare FactB
    factA: FactA
    propB : String
end

POM:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <properties>
    <generateModel>YES</generateModel>
    <runtime.version>7.20.0.Final</runtime.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
  </properties>

  <groupId>org</groupId>
  <artifactId>example</artifactId>
  <version>1.0.0</version>
  <packaging>kjar</packaging>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-bom</artifactId>
                <version>${runtime.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.kie</groupId>
      <artifactId>kie-api</artifactId>
    </dependency>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-model-compiler</artifactId>
    </dependency>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-canonical-model</artifactId>
    </dependency>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.drools</groupId>
      <artifactId>drools-compiler</artifactId>
    </dependency>
  </dependencies>

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

mvn clean package的输出

[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------------< org:example >-----------------------------
[INFO] Building example 1.0.0
[INFO] --------------------------------[ kjar ]--------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ example ---
[INFO] Deleting C:\Projects\t\kie-maven-plugin-example\target
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ example ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ example ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 1 source file to C:\Projects\t\kie-maven-plugin-example\target\classes
[INFO]
[INFO] --- kie-maven-plugin:7.20.0.Final:generateModel (default-generateModel) @ example ---
[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-core/7.20.0.Final/drools-core-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.core.io.impl.ResourceFactoryServiceImpl

[INFO] Adding Service org.drools.core.marshalling.impl.MarshallerProviderImpl

[INFO] Adding Service org.drools.core.concurrent.ExecutorProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-compiler/7.20.0.Final/drools-compiler-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.compiler.kie.builder.impl.KieServicesImpl

[INFO] Adding Service org.drools.compiler.builder.impl.KnowledgeBuilderFactoryServiceImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-model-compiler/7.20.0.Final/drools-model-compiler-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.modelcompiler.CanonicalKieModuleProvider

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/kie/kie-internal/7.20.0.Final/kie-internal-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.kie.internal.services.KieAssemblersImpl

[INFO] Adding Service org.kie.internal.services.KieRuntimesImpl

[INFO] Adding Service org.kie.internal.services.KieWeaversImpl

[INFO] Adding Service org.kie.internal.services.KieBeliefsImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-decisiontables/7.20.0.Final/drools-decisiontables-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.decisiontable.DecisionTableProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-scorecards/7.20.0.Final/drools-scorecards-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.scorecards.ScoreCardProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/kie-pmml/7.20.0.Final/kie-pmml-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service +org.kie.pmml.assembler.PMMLAssemblerService

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/jbpm/jbpm-bpmn2/7.20.0.Final/jbpm-bpmn2-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.jbpm.bpmn2.BPMN2ProcessProviderImpl

[INFO] Adding Service org.jbpm.bpmn2.xml.XmlProcessDumperFactoryServiceImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/jbpm/jbpm-flow-builder/7.20.0.Final/jbpm-flow-builder-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.jbpm.process.builder.ProcessBuilderFactoryServiceImpl

[INFO] Adding Service +org.jbpm.assembler.BPMN2AssemblerService

[INFO] Adding Service +org.jbpm.weaver.BPMN2WeaverService

[INFO] Adding Service +org.jbpm.assembler.DRFAssemblerService

[INFO] Adding Service +org.jbpm.weaver.DRFWeaverService

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/jbpm/jbpm-flow/7.20.0.Final/jbpm-flow-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.jbpm.marshalling.impl.ProcessMarshallerFactoryServiceImpl

[INFO] Adding Service org.jbpm.process.instance.ProcessRuntimeFactoryServiceImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/jbpm/jbpm-case-mgmt-cmmn/7.20.0.Final/jbpm-case-mgmt-cmmn-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.jbpm.casemgmt.cmmn.CMMNCaseProviderImpl

[INFO] Adding Service +org.jbpm.casemgmt.cmmn.assembler.CMMNAssemblerService

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-workbench-models-guided-dtable/7.20.0.Final/drools-workbench-models-guided-dtable-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.workbench.models.guided.dtable.backend.GuidedDecisionTableProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-workbench-models-guided-template/7.20.0.Final/drools-workbench-models-guided-template-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.workbench.models.guided.template.backend.GuidedRuleTemplateProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/drools/drools-workbench-models-guided-scorecard/7.20.0.Final/drools-workbench-models-guided-scorecard-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service org.drools.workbench.models.guided.scorecard.backend.GuidedScoreCardProviderImpl

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/optaplanner/optaplanner-core/7.20.0.Final/optaplanner-core-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service +org.optaplanner.core.impl.solver.kie.KieSolverAssemblerService

[INFO] Loading kie.conf from  jar:file:/C:/Users/Dmitri/.m2/repository/org/kie/kie-dmn-core/7.20.0.Final/kie-dmn-core-7.20.0.Final.jar!/META-INF/kie.conf in classloader ClassRealm[extension>org.kie:kie-maven-plugin:7.20.0.Final, parent: sun.misc.Launcher$AppClassLoader@7852e922]
[INFO] Adding Service +org.kie.dmn.core.assembler.DMNAssemblerService

[INFO] Adding Service +org.kie.dmn.core.runtime.DMNRuntimeService

[INFO] Adding Service +org.kie.dmn.core.weaver.DMNWeaverService

[INFO] Artifact not fetched from maven: org.drools:drools-bom:${runtime.version}. To enable the KieScanner you need kie-ci on the classpath
[ERROR] package org.example
public class FactB implements org.drools.core.factmodel.GeneratedFact, java.io.Serializable {

    public FactB() {
    }

    public FactB(FactA factA, String propB) {
        super();
        this.factA = factA;
        this.propB = propB;
    }

    @org.kie.api.definition.type.Position(value = 0)
    private FactA factA;

    public void setFactA(FactA factA) {
        this.factA = factA;
    }

    public FactA getFactA() {
        return factA;
    }

    @org.kie.api.definition.type.Position(value = 1)
    private String propB;

    public void setPropB(String propB) {
        this.propB = propB;
    }

    public String getPropB() {
        return propB;
    }

    @Override()
    public String toString() {
        return "FactB" + "( " + "factA=" + factA + ", " + "propB=" + propB + " )";
    }
}
[ERROR] Unable to build KieBaseModel:defaultKieBase
CompilationProblemErrorResult: cannot find symbol
  symbol:   class FactA
  location: package org.example
CompilationProblemErrorResult: cannot find symbol
  symbol:   class FactA
  location: class org.example.FactB
CompilationProblemErrorResult: cannot find symbol
  symbol:   class FactA
  location: class org.example.FactB
CompilationProblemErrorResult: cannot find symbol
  symbol:   class FactA
  location: class org.example.FactB
CompilationProblemErrorResult: cannot find symbol
  symbol:   class FactA
  location: class org.example.FactB

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  6.465 s
[INFO] Finished at: 2019-04-26T09:00:16-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.kie:kie-maven-plugin:7.20.0.Final:generateModel (default-generateModel) on project example: Execution default-generateModel of goal org.kie:kie-maven-plugin:7.20.0.Final:generateModel failed: Unable to get KieModule, Errors Existed: Error Messages:
[ERROR] Message [id=1, kieBase=defaultKieBase, level=ERROR, path=null, line=5, column=0
[ERROR]    text=cannot find symbol
[ERROR]   symbol:   class FactA
[ERROR]   location: package org.example]
[ERROR] Message [id=2, kieBase=defaultKieBase, level=ERROR, path=null, line=12, column=0
[ERROR]    text=cannot find symbol
[ERROR]   symbol:   class FactA
[ERROR]   location: class org.example.FactB]
[ERROR] Message [id=3, kieBase=defaultKieBase, level=ERROR, path=null, line=19, column=0
[ERROR]    text=cannot find symbol
[ERROR]   symbol:   class FactA
[ERROR]   location: class org.example.FactB]
[ERROR] Message [id=4, kieBase=defaultKieBase, level=ERROR, path=null, line=21, column=0
[ERROR]    text=cannot find symbol
[ERROR]   symbol:   class FactA
[ERROR]   location: class org.example.FactB]
[ERROR] Message [id=5, kieBase=defaultKieBase, level=ERROR, path=null, line=25, column=0
[ERROR]    text=cannot find symbol
[ERROR]   symbol:   class FactA
[ERROR]   location: class org.example.FactB]
[ERROR] ---
[ERROR] Warning Messages:
[ERROR] ---
[ERROR] Info Messages:
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

1 个答案:

答案 0 :(得分:0)

这可能是在可执行模型的声明类型生成中的错误。

您能在这里张贴您的复制人吗?

https://issues.jboss.org/projects/DROOLS/issues

同时,作为一种变通办法,您可以在以声明的类型使用类时尝试使用完全限定名称吗?

package org.example

declare FactB
    factA: org.example.FactA
    propB : String
end

我已经针对当前的主服务器进行了尝试,并且可以正常工作。

感谢您的帮助

这是在此处修复的错误

https://github.com/kiegroup/drools/commit/c36f3ebf1f02e54742c8b4056e7b64bb5deaed07

感谢报告