0

I am using Drools 6.0.1 and making use of the new Maven-based architecture to deploy my rules.

The POM of the project looks like shown at the end of this post.

I start the project with the parameter -Dkie.maven.settings.custom="X:\\maven2\\settings.xml" to use a separate Maven repository for Drools. That settings.xml is also shown below.

When I run the project (.java shown at the end), the drools-internal maven, namely Aether, still adds the central repository to its internal configuration. This is bad because obviously the system should run offline.

The output of running then is:

DEBUG [main] (KieRepositoryImpl.java:91) - KieModule Lookup. ReleaseId de.itm.droolstest:x123:1.0.1 was not in cache, checking classpath
DEBUG [main] (KieRepositoryImpl.java:97) - KieModule Lookup. ReleaseId de.itm.droolstest:x123:1.0.1 was not in cache, checking maven repository
DEBUG [main] (Logs.java:390) - Add publisher: com.google.inject.internal.InjectorImpl@784eb2c

-----[explicit bindings]-------------------------------------------------------
0. ProviderInstanceBinding{key=Key[type=com.google.inject.Injector, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Injector>}
1. ProviderInstanceBinding{key=Key[type=java.util.logging.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<Logger>}
2. ProviderInstanceBinding{key=Key[type=org.slf4j.Logger, annotation=[none]], source=[unknown source], scope=Scopes.NO_SCOPE, provider=Provider<org.slf4j.Logger>}
3. InstanceBinding{key=Key[type=com.google.inject.Stage, annotation=[none]], source=[unknown source], instance=DEVELOPMENT}
[...] (many more lines removed for brevity)
202. ConstructorBinding{key=Key[type=org.apache.maven.lifecycle.internal.LifecycleDebugLogger, annotation=[none]], source=ClassRealm[maven, parent: ClassRealm[maven-parent, parent: null]], scope=Scopes.SINGLETON}
-----[implicit bindings]-------------------------------------------------------
-------------------------------------------------------------------------------

 INFO [pool-1-thread-1] (NettyAsyncHttpProvider.java:199) - Number of application's worked threads is 8
DEBUG [pool-1-thread-1] (NettyAsyncHttpProvider.java:948) - 
Non cached request 
DefaultHttpRequest(chunked: false)
HEAD /nexus/content/groups/public/de/droolstest/x123/1.0.1/x123-1.0.1.jar HTTP/1.1
Host: nexus.my-domain.de:8081
Pragma: no-cache
Cache-Control: no-cache, no-store
Accept-Encoding: gzip
Connection: keep-alive
Accept: */*
User-Agent: Aether

using Channel 
[id: 0x0fd71519]

DEBUG [New I/O client worker #1-1] (NettyAsyncHttpProvider.java:1048) - 

Request DefaultHttpRequest(chunked: false)
HEAD /nexus/content/groups/public/de/itm/droolstest/x123/1.0.1/x123-1.0.1.jar HTTP/1.1
Host: nexus.my-domain.de:8081
Pragma: no-cache
Cache-Control: no-cache, no-store
Accept-Encoding: gzip
Connection: keep-alive
Accept: */*
User-Agent: Aether

Response DefaultHttpResponse(chunked: false)
HTTP/1.1 404 The server has not found anything matching the request URI
Date: Tue, 11 Mar 2014 09:42:48 GMT
Set-Cookie: rememberMe=deleteMe; Path=/nexus; Max-Age=0; Expires=Mon, 10-Mar-2014 09:42:48 GMT
Date: Tue, 11 Mar 2014 09:42:48 GMT
Vary: Accept-Charset, Accept-Encoding, Accept-Language, Accept
Server: Noelios-Restlet-Engine/1.1.6-SONATYPE-5348-V4
Content-Type: text/html;charset=ISO-8859-1
Cache-Control: must-revalidate,no-cache,no-store
Content-Length: 1533

DEBUG [New I/O client worker #1-1] (NettyConnectionsPool.java:147) - Adding uri: http://nexus.my-domain.de:8081 for channel [id: 0x0fd71519, /192.168.100.113:51272 => nexus.my-domain.de/192.168.100.145:8081]
Exception in thread "main" Exception in thread "FileRepositoryConnector-1" java.lang.IllegalArgumentException: number of transferred bytes cannot be negative
    at org.sonatype.aether.util.listener.DefaultTransferEvent.setTransferredBytes(DefaultTransferEvent.java:123)
    at org.sonatype.aether.connector.file.FileRepositoryWorker.run(FileRepositoryWorker.java:299)
    at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)
java.lang.IllegalArgumentException: number of transferred bytes cannot be negative
    at org.sonatype.aether.util.listener.DefaultTransferEvent.setTransferredBytes(DefaultTransferEvent.java:123)
    at org.sonatype.aether.connector.file.FileRepositoryWorker.run(FileRepositoryWorker.java:299)
    at org.sonatype.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:60)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:744)

(The artifact is, of course, in that x:/maven2 repository)

As you can see, the system tries to connect to our own Nexus, which is configured in the global settings.xml, the one used for building the project.

So, my question(s) would be: * how can I configure Drools to run its Maven completely offline * How can I prevent Drools' Maven to take the project's pom.xml as configuration? That pom.xml should only be used when building the project, not at runtime! Can that be prevented?

Any help is appreciated!


And now the configuration files.

Project's pom.xml:

<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.demo</groupId>
    <artifactId>kieTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.drools</groupId>
                <artifactId>drools-bom</artifactId>
                <type>pom</type>
                <version>6.0.1.Final</version>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-api</artifactId>
        </dependency>
        <dependency>
            <groupId>org.kie</groupId>
            <artifactId>kie-ci</artifactId>
        </dependency>
        <dependency>
            <groupId>org.drools</groupId>
            <artifactId>drools-compiler</artifactId>
            <scope>runtime</scope>
        </dependency>
    </dependencies>
</project>

The x:\maven2\settings.xml (the one for drools):

<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:/maven2/repository</localRepository>
    <interactiveMode>false</interactiveMode>
    <offline>true</offline>

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

            <repositories>
                <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>

The actual Java class: package kieTest;

import org.kie.api.*;

public class MainKieTest {

    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        KieRepository repository = ks.getRepository();
        ReleaseId releaseId = ks.newReleaseId("de.test.droolstest", "x123", "1.0.1");
        KieContainer kieContainer = ks.newKieContainer(releaseId);
    }
}
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77

2 Answers2

0

It is normal for Nexus to contain release artifacts, not just dependencies which you use during builds. However, it is possible to block its use. Presumably your ~/.m2/.settings.xml has been configured to go to your Nexus repository instead of central, when looking for artifacts. Similar to the way you might configure Maven to go to the Nexus proxy instead of central, you just change ~/.m2/.settings to disable downloads of release and snapshot artifacts from central.

<repositories>
  <repository>
    <id>central</id>
    <url>http://repo1.maven.org/maven2</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>false</enabled>
    </snapshots>
  </repository>
</repositories>
Steve
  • 9,270
  • 5
  • 47
  • 61
  • But I don't want to use _any_ external repository, may it be central or our Nexus, to be used by the Drools-Maven. And above snippet already IS in the `settings.xml` used for Drools. – Dominik Sandjaja Mar 11 '14 at 12:03
  • Does yours say that releases and snapshots are disabled? If so then you're already not using it. – Steve Mar 11 '14 at 13:14
  • Yes. I only have that `settings.xml` on a freshly installed system, no maven installed - the program still tries to contact repo1.maven.org. – Dominik Sandjaja Mar 11 '14 at 14:38
  • 1
    You could just change the URL for central to localhost if you don't want it logging anything about your Nexus install. – Steve Mar 11 '14 at 15:04
  • That would be a good idea, I'll try that out. But in the meantime I found the source problem for my issue, see my answer. – Dominik Sandjaja Mar 12 '14 at 08:47
0

I found the underlying problem: Bug No. 1065984 in RedHat's Bugzilla. It is about the embedded maven not respecting the settings configured in that explicit settings.xml. The bugfix was released in Drools 6.1.0.Beta1 which got published in the Maven repositories on friday - that is why I didn't find it until shortly.

With the new version, the offline aspect is working much better, at least it won't connect to a remote server just like this.

Still, there is the problem, that the effective Maven configuration/pom does take into account the POM which is used for the project Drools is running inside. That is bad, because I don't want to put all those dependencies into the Drools-Maven-Repository. But that is for another question.

Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77