1

In my project, there is Karaf feature XML file contains all OSGi bundles. Now, this is used as dependency in other maven project's pom.xml file.

<dependency>
  <groupId>a.b.c</groupId>
  <artifactId>dummyfeature</artifactId>
  <type>xml</type>
  <classifier>features</classifier>
  <version>1.0.0</version>
</dependency>

Now, following code is being used to install above feature.

KarafDistributionOption.features(
                 maven()
                .groupId("a.b.c")
                .artifactId("dummyfeature")
                .version("1.0.0")
                .type("xml")
                .classifier("features"), "dummyfeature")

Is there a way to exclude a particular OSGi bundle from above feature programtically?

Anshul Singhal
  • 1,983
  • 20
  • 25

1 Answers1

2

https://issues.apache.org/jira/browse/KARAF-5376 provides a way to alter the features read from XML file. You can:

  • blacklist some bundles
  • blacklist some features
  • override some bundles (like changing version or even group/artifact IDs)
  • override entire features

See this comment for overview of the mechanism. There's no documentation fragment yet (I didn't have time to do it). But for your particular case, you should add etc/org.apache.karaf.features.xml file with this content:

<?xml version="1.0" encoding="UTF-8"?>
<!--
    Configuration generated by Karaf Assembly Builder
-->
<featuresProcessing xmlns="http://karaf.apache.org/xmlns/features-processing/v1.0.0">
    <blacklistedBundles>
        <!-- there are several patterns you can use here -->
        <bundle>mvn:groupId/artifactId</bundle>
        <bundle>mvn:groupId/artifactId/1.0</bundle>
        <bundle>mvn:groupId/artifactId/[1,2)</bundle>
    </blacklistedBundles>
</featuresProcessing>
Grzegorz Grzybek
  • 6,152
  • 3
  • 29
  • 42
  • Thanks for your response. I will attempt it and update here. – Anshul Singhal Dec 03 '18 at 08:59
  • I was just accessing URL http://karaf.apache.org/xmlns/features-processing/v1.0.0 specified as namespace for feature processing and is not accessible. Ideally it should be. Correct? – Anshul Singhal Dec 03 '18 at 10:22
  • The XSD which defines this XML namespace is available only within source code for now. I'll publish it when working on documentation, but for now, it's NOT needed to use this `etc/org.apache.karaf.features.xml`. If you want to know full schema, it's in https://github.com/apache/karaf/blob/master/features/core/src/main/resources/org/apache/karaf/features/karaf-features-processing-1.0.0.xsd – Grzegorz Grzybek Dec 03 '18 at 14:53
  • is it correct to say that Karaf version 4.2.1 should be used to leverage this capability? Karaf version lower than 4.2.x will not support it. – Anshul Singhal Dec 04 '18 at 09:09
  • The version where it's fixed is `4.2.0.M2`, but there were some improvements (corner cases later). So 4.2.1 is safe. – Grzegorz Grzybek Dec 04 '18 at 13:05
  • Is there a way to blacklist bundles from a feature in earlier versions of Karaf (i.e. 3.0.6) as upgrading Karaf to 4.2.1 is impacting whole system in my project? – Anshul Singhal Dec 05 '18 at 06:02
  • I don't think there's clean way. You could have `etc/overrides.properties` with *newer* version of some bundle and kind of hack this bundle to be empty... But that's really tricky way to do it... – Grzegorz Grzybek Dec 05 '18 at 10:25
  • @AnshulSinghal Were you able exclude bundles from features somehow? I'm in the same boat as you - trying to exclude specific bundles from Karaf 3.0.2. – Chandan Hegde Feb 16 '22 at 09:57