Does Karaf support downloading of transitive dependencies from maven central?

旧时模样 提交于 2019-12-06 07:31:18

You can use the karaf-maven-plugin to create a feature file from maven dependencies. This will resolve transitive dependencies.

I found a way of doing this in a relatively OSGi standard way using Maven. It uses the maven-dependency-plugin to create a repository that only contains the dependencies that is required on the runtime scope.

Then the maven-bundle-plugin:index goal is executed to create the repository.xml file.

At this point in the target you have a valid obr repository, the maven-assembly-plugin can be used to package it up as needed.

The following pom.xml snippet will do what is required.

        <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-runtime-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <copyPom>true</copyPom>
                        <useRepositoryLayout>true</useRepositoryLayout>
                        <includeScope>runtime</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <executions>
                <execution>
                    <id>index</id>
                    <goals>
                        <goal>index</goal>
                    </goals>
                    <phase>verify</phase>
                    <configuration>
                        <mavenRepository>${project.build.directory}/dependency</mavenRepository>
                    </configuration>
                </execution>
            </executions>
        </plugin>

As for Karaf, this a bundle along with its transitive dependencies can be installed without using Karaf's feature.xml using the following commands:

features:install obr
obr:addUrl [location of the OBR repository, can be file:///....]
obr:deploy [symbolicname-of-bundle]
start [symbolicname-of-bundle]

And voila.

Note that this will only load up the bundles that are referenced by the bundle you had specified so if you're using something like Blueprint where in theory it shouldn't know about the other bundles, then you have to explicitly deploy them or create an uber bundle that will contain the bundles you have (like a feature/product)

As far as I know, the best you can do is use Maven to download all the dependancies, and then use the Felix bnd plugin to convert your local (or remote) repository into an OBR that you can use with Karaf.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!