避免在运行Drools时解析项目pom.xml

时间:2014-03-13 15:31:53

标签: java maven drools kie

这是a question I asked earlier的后续问题。

我正在使用以下(缩短的)pom.xml的项目中使用Drools 6.1.0.Beta1:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.test.configuration</groupId>
    <artifactId>someTest</artifactId>
    <version>0.7.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>droolsTest</name>

    <parent>
            <groupId>de.test</groupId>
            <artifactId>maven-parent</artifactId>
            <version>0.3</version>
    </parent>

    <dependencies>
            <!-- The Drools rule engine -->
            <dependency>
                    <groupId>org.drools</groupId>
                    <artifactId>drools-core</artifactId>
                    <version>6.1.0.Beta1</version>
            </dependency>
            <dependency>
                    <groupId>org.drools</groupId>
                    <artifactId>drools-compiler</artifactId>
                    <version>6.1.0.Beta1</version>
            </dependency>
            <!-- getting maven artefacts -->
            <dependency>
                    <groupId>org.kie</groupId>
                    <artifactId>kie-ci</artifactId>
                    <version>6.1.0.Beta1</version>
            </dependency>
    </dependencies>
</project>

对于在KIE / Drools中使用的内部maven,我有一个单独的settings.xml,它配置了属性-Dkie.maven.settings.custom =&#34; X:\ droolsmaven \ settings.xml&# 34; 该文件的内容是:

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                  http://maven.apache.org/xsd/settings-1.0.0.xsd">

    <localRepository>x:/droolsmaven/repository</localRepository>

    <profiles>
            <profile>
                    <id>mavenDroolsProfile</id>
                    <activation>
                            <activeByDefault>true</activeByDefault>
                    </activation>

                    <repositories>

                            <repository>
                                    <id>someRepo</id>
                                    <url>http://1.2.3.4</url>
                                    <releases>
                                            <enabled>false</enabled>
                                    </releases>
                                    <snapshots>
                                            <enabled>false</enabled>
                                    </snapshots>
                            </repository>

                            <repository>
                                    <id>central</id>
                                    <url>http://repo1.maven.org/maven2</url>
                                    <releases>
                                    <enabled>false</enabled>
                                    </releases>
                                    <snapshots>
                                            <enabled>false</enabled>
                                    </snapshots>
                            </repository>
                    </repositories>
            </profile>
    </profiles>

</settings>

在该本地存储库中,部署了之后使用的相应工件,该工件正在运行,并使用非maven项目进行确认。

现在,当尝试在上面提到的pom定义的maven项目中运行以下代码时,我得到了此代码块之后提到的错误:

public class MainKieTest {

public static void main(String[] args) {
    KieServices ks = KieServices.Factory.get();

    KieRepository repository = ks.getRepository();
    ReleaseId releaseId = ks.newReleaseId("de.test.package", "artifact", "1.0.1");

    KieContainer kieContainer = ks.newKieContainer(releaseId);

    KieScanner kieScanner = ks.newKieScanner(kieContainer);
    kieScanner.scanNow();
}
}

错误是:

DEBUG [main] (KieRepositoryImpl.java:92) - KieModule Lookup. ReleaseId de.test.package:artifact:1.0.1 was not in cache, checking classpath DEBUG [main] (KieRepositoryImpl.java:98) - KieModule Lookup. ReleaseId de.test.package:artifact:1.0.1 was not in cache, checking maven repository  WARN [main] (MavenSettings.java:47) - Environment variable M2_HOME is not set DEBUG [main] (Logs.java:390) - Add publisher: com.google.inject.internal.InjectorImpl@5221dfe5

-----[explicit bindings]-------------------------------------------------------
0. ProviderInstanceBinding{key=Key[type=com.google.inject.Injector, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Injector>} [...] lines cut for brevity 198. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.DefaultSchedules, annotation=[none]], source=ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]], scope=Scopes.SINGLETON} -----[implicit bindings]-------------------------------------------------------
-------------------------------------------------------------------------------

Exception in thread "main" java.lang.RuntimeException: org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact de.test:maven-parent:pom:0.3 and 'parent.relativePath' points at wrong local POM @ line 15, column 10

        at org.kie.scanner.embedder.MavenProjectLoader.parseMavenPom(MavenProjectLoader.java:21)
        at org.kie.scanner.embedder.MavenProjectLoader.loadMavenProject(MavenProjectLoader.java:48)
        at org.kie.scanner.Aether.<init>(Aether.java:44)
        at org.kie.scanner.Aether.getAether(Aether.java:54)
        at org.kie.scanner.MavenRepository.getMavenRepository(MavenRepository.java:53)
        at org.kie.scanner.ArtifactResolver.<init>(ArtifactResolver.java:36)
        at org.kie.scanner.KieRepositoryScannerImpl.getArtifactResolver(KieRepositoryScannerImpl.java:77)
        at org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:87)
        at org.kie.scanner.KieRepositoryScannerImpl.loadArtifact(KieRepositoryScannerImpl.java:83)
        at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.loadKieModuleFromMavenRepo(KieRepositoryImpl.java:114)
        at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:100)
        at org.drools.compiler.kie.builder.impl.KieRepositoryImpl.getKieModule(KieRepositoryImpl.java:77)
        at org.drools.compiler.kie.builder.impl.KieServicesImpl.newKieContainer(KieServicesImpl.java:106)
        at de.test.configuration.kie.MainKieTest.main(MainKieTest.java:40)
Caused by: org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM: Could not find artifact de.test:maven-parent:pom:0.3 and 'parent.relativePath' points at wrong local POM @ line 15, column 10

        at org.apache.maven.project.DefaultProjectBuilder.build(DefaultProjectBuilder.java:363)
        at org.kie.scanner.embedder.MavenEmbedder.buildProjects(MavenEmbedder.java:335)
        at org.kie.scanner.embedder.MavenEmbedder.readProjects(MavenEmbedder.java:319)
        at org.kie.scanner.embedder.MavenEmbedder.readProject(MavenEmbedder.java:312)
        at org.kie.scanner.embedder.MavenProjectLoader.parseMavenPom(MavenProjectLoader.java:19)
        ... 13 more

问题似乎是,Drools / KIE内部的Maven也尝试构建完整的依赖树,由KIE运行的项目的pom.xml给出。

恕我直言,这不应该是,因为在运行时使用的为Drools部署的maven工件独立于用于构建项目本身的工件;那些在构建时需要。

这个问题只是误解了我认为Drools应该如何运作还是一个真正的错误?

1 个答案:

答案 0 :(得分:4)

简短更新:

我与Drools的一位开发人员交谈,这似乎是一个实际的功能稍有不妥。可以找到错误here,邮件列表中的相应问题是here,修复此问题的提交是here

感谢Mario Fusco的快速解决方案!