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

StackOverflow https://stackoverflow.com/questions/5017687

Question

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.

Was it helpful?

Solution

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top