1

Is there a way to deploy a programatically created Drools 6 artifact to the underlying maven repository? I do NOT want to explicitly somehow call mvn deploy but do that from the program itself:

public static void main(String[] args) {
    String ruleString = "rule \"TestRule\"\nthen\nSystem.out.println(\"This is a testrule.\");\nend";

    KieServices kieServices = KieServices.Factory.get();

    KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
    KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel("testbase1").setDefault(true);
    KieSessionModel kieSessionModel = kieBaseModel.newKieSessionModel("testsession1").setDefault(true).setType(KieSessionModel.KieSessionType.STATELESS);

    KieFileSystem kieFileSystem = kieServices.newKieFileSystem();
    kieFileSystem.generateAndWritePomXML(new ReleaseIdImpl("de.itm.test", "testartifact", "0.0.1-SNAPSHOT"));
    kieFileSystem.write("src/main/resources/testbase1/rule1.drl", ruleString);

    KieBuilder kieBuilder = kieServices.newKieBuilder(kieFileSystem).buildAll();

    // how to now deploy the new artifact so it is available on disc, e.g. in ~/.m2/repository/de/itm/test/test/testartifact/0.0.1-SNAPSHOT/ ?
}
Dominik Sandjaja
  • 6,326
  • 6
  • 52
  • 77

1 Answers1

4

Here you can see a unit test that does what you are asking for:

https://github.com/kiegroup/drools/blob/master/kie-ci/src/test/java/org/kie/scanner/KieScannerIncrementalCompilationTest.java#L63

Basically:

MavenRepository repository = MavenRepository.getMavenRepository();
repository.deployArtifact(releaseId, kJar1, kPom);
Joe Skora
  • 14,735
  • 5
  • 36
  • 39
Edson Tirelli
  • 3,891
  • 20
  • 23
  • Thank you, I also found the https://github.com/droolsjbpm/droolsjbpm-integration/blob/master/kie-remote/kie-services-client/src/main/java/org/kie/services/client/deployment/KieModuleDeploymentHelperImpl.java . I will try to re-implement that part of Guvnor/KIE-WB in my own program, although I am currently struggling with the resourceFilePaths ... – Dominik Sandjaja Mar 13 '14 at 09:28
  • Does this upload to KIE' maven repo in remote kie repositroy? – Arun George Nov 24 '15 at 09:34
  • @ArunGeorge it does if you configured the remote repo in the maven settings.xml file. – Edson Tirelli Nov 25 '15 at 17:20
  • @Edson . Can you provide an example.I have seen the kie-ci testcases and did not find anything which does this. – Arun George Dec 02 '15 at 10:37
  • The test I linked on my answer above uses a custom settings.xml file here: https://github.com/droolsjbpm/drools/blob/master/kie-ci/src/test/filtered-resources/kie-ci-tests-custom-settings.xml – Edson Tirelli Dec 02 '15 at 15:55