Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

karaf-maven-plugin: Defining a dependency as a feature

I am trying to make the karaf-maven-plugin generate a feature file for my application. The application depends on the cxf feature, but i can't seem to make the plugin generate the feature xml to reflect this.

Cutout from my feature module:

    <dependencies>
        <dependency>
            <groupId>com.test.test</groupId>
            <artifactId>test</artifactId>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.karaf.tooling</groupId>
                    <artifactId>karaf-maven-plugin</artifactId>
                    <version>3.0.3</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>karaf-maven-plugin</artifactId>
          <configuration>
            <startLevel>80</startLevel>
        <includeTransitiveDependency>true</includeTransitiveDependency>
        <aggregateFeatures>false</aggregateFeatures>
          </configuration>
        </plugin>
        </plugins>
    </build>

The dependencies from my module:

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.core</artifactId>
                <version>5.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.compendium</artifactId>
                <version>5.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.felix</groupId>
                <artifactId>org.apache.felix.configadmin</artifactId>
                <version>1.8.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.2.8</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxrs</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- use extension providers -->
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-rs-extension-providers</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- use Jackson -->
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-jaxrs</artifactId>
                <version>1.9.13</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-xc</artifactId>
                <version>1.9.13</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-security</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-policy</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-addr</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-rs-client</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http-hc</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf.karaf</groupId>
                <artifactId>apache-cxf</artifactId>
                <version>${cxf.version}</version>
                <classifier>features</classifier>
                <type>xml</type>
            </dependency>


            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.3.2</version>
            </dependency>
        </dependencies>

As you can see, i have tried to define the feature artifact as a compile scoped dependency, as well as commons lang. Everything else is scoped as provided.

            <dependency>
                <groupId>org.apache.cxf.karaf</groupId>
                <artifactId>apache-cxf</artifactId>
                <version>${cxf.version}</version>
                <classifier>features</classifier>
                <type>xml</type>
            </dependency>


            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.3.2</version>
            </dependency>

In the resulting features.xml file, the commons bundle is registered, but the feature is not:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
    <feature name="feature" version="0.1-SNAPSHOT" description="test-feature">
        <details>test</details>
        <bundle start-level="80">mvn:com.test.test/test/0.1-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.apache.commons/commons-lang3/3.3.2</bundle>
    </feature>
</features>

I would like to end up with this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
    <feature name="feature" version="0.1-SNAPSHOT" description="test-feature">
        <details>test</details>
        <feature version="3.0.2">cxf</feature>
        <bundle start-level="80">mvn:com.test.test/test/0.1-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.apache.commons/commons-lang3/3.3.2</bundle>
    </feature>
</features>

Slight update: When i add <aggregateFeatures>true</aggregateFeatures> to the plugin config, the entire cxf feature is unpacked into my features.xml file, but the features dependencies like "cxf" still does not appear in the geneated feature.

like image 997
Martin Nielsen Avatar asked Apr 15 '15 08:04

Martin Nielsen


1 Answers

IMHO this is something wrong or not completed in karaf-maven-plugin. I have had the same problem. For me the solution I found is to add a feature.xml template under src/main/feature, just with the features and other files (configfiles) I need. In your case would be something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
    <feature name="feature" version="${yourprojectversion}" description="test-feature">
        <feature version="${cxf.version}">cxf</feature>
    </feature>
</features>

I use also: <aggregateFeatures>true</aggregateFeatures>

Note that in my feature template I have use some custom maven properties for version handling defined in the pom.xml. At the end you will get the feature you are expecting to.

like image 140
Jorge Martinez Avatar answered Oct 23 '22 09:10

Jorge Martinez