Use maven tycho to build with a manifest entry Bundle-ClassPath that gets downloaded by the maven-dependency-plugin
Asked Answered
A

2

8

I have an eclipse plugin with this manifest:

...
Bundle-ClassPath: .,
 lib/drools-api.jar,
 lib/drools-core.jar,
...

Now we don't want to put drools-api.jar and drools-core.jar in source control, so we use a plugin to fetch them from the maven repository:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-bundle-classpath-libs</id>
        <phase>validate</phase>
        <goals>
          <goal>copy</goal>
        </goals>
        <configuration>
          <outputDirectory>lib</outputDirectory>
          <overWriteReleases>true</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
          <stripVersion>true</stripVersion>
          <artifactItems>
            <artifactItem>
              <groupId>org.drools</groupId>
              <artifactId>drools-api</artifactId>
            </artifactItem>
            <artifactItem>
              <groupId>org.drools</groupId>
              <artifactId>drools-core</artifactId>
            </artifactItem>
            ...

However, the first time we build this module, it fails, because this happens:

[WARNING] Missing classpath entry lib/drools-api.jar ...
[WARNING] Missing classpath entry lib/drools-core.jar ...
...
[INFO] --- maven-dependency-plugin:2.1:copy (copy-bundle-classpath-libs) ... ---
...
[INFO] Copying drools-api-5.2.0-SNAPSHOT.jar to .../lib/drools-api.jar
[INFO] Copying drools-core-5.2.0-SNAPSHOT.jar to .../lib/drools-core.jar
...
[INFO] --- maven-osgi-compiler-plugin:0.10.0:compile (default-compile) ... ---
...
[INFO] Compiling 458 source files to ...
// ERROR because drools-api is not in the compilation classpath

If we just build it again, it succeeds, because the jars are already in the lib directory before the builds starts: there are no warnings and the jars are in the compilation classpath.

How can we fix this so we don't need to commit the jars in source control and still use Bundle-ClassPath?

Note: the current implementation of the plugin requires us to use Bundle-ClassPath: using Require-Bundle instead is not an option.

Ashlar answered 16/2, 2011 at 14:34 Comment(4)
Have you put the drools-api jar into your dependencies or only in the configuration of the maven-dependency plugin? Other hint: Why not using felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.htmlEcg
@khmarbaise: I tried both, even with pomDependencies consider, but it can never compile it if the lib dir is emptyAshlar
Hm..Have you tried the goal copy-dependencies instead ?Ecg
Yes, pomDependencies:consider and copy-dependencies still aren't enough to get it in the compilation classpath in the first build.Ashlar
L
2

this is a known bug.

see https://issues.sonatype.org/browse/TYCHO-577

Ley answered 16/2, 2011 at 16:43 Comment(0)
F
1

I have tried to do similar thing and I have got an impression that this will not work.

Seems like maven-dependency-plugin requires compile classpath to be resolved in order to download JARs (even when you specify dependencies via <artifactItems>).

As a result, Tycho-driven classpath resolution is executed before JARs are downloaded, so they do not make their way into the classpath. Kind of chicken and egg issue.

To solve that issue, I have created a separate profile "download-deps" which I used to refresh libraries directory (like: mvn -Pdownload-deps validate).

This approcha does not work well, though, since if there are bundle B that import package provided by bundle A, which in turn embeds JARs that contains that package, compilation of B will fail with unresolved dependency. Therefore, you have to run this command until all JARs are downloaded. Very ugly.

Forespeak answered 16/2, 2011 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.