bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
530 stars 305 forks source link

Bndtools / Maven with sources JAR #6109

Closed thahnen closed 3 months ago

thahnen commented 5 months ago

TL;DR: I didn't find any concrete information on how to include the sources of JAR archives in the sources.jar that are configured using the -includeresource statement (e.g. -includeresource: lib/guava.jar=guava-*.jar;lib=true does not pack the sources of the guava library into the sources JAR archive).

I found a bit of conflicting information regarding packaging the sources when using Maven. There is THIS thread that seems to not have an answer provided and I found THIS snippet. But if I understood correctly the latter is used to follow the OSGi guidelines and have the sources packed into the normal JAR archive instead of the sources.jar.

So is there any possibility? I'm currently using two different bnd files in the Maven build that are used via the bnd-process goal. The first one uses -includeresource statements like the one mentioned above (but a bit more complicated), and the other one has none. It is a bit confusing, I was also trying to use -sources: true but it didn't do anything.

So my question is: Is there something possible? Does the -includeresource have an option for that or do I have to invoke something else? Is it possible with Maven or does it require some manual magic perhaps?

pkriens commented 5 months ago

you can include them explicitly?

-includeresource: 
    lib/guava.jar=guava-*.jar;lib=true, \
    OSGI-OPT/src=@guava-sources.jar
thahnen commented 5 months ago

I'm using Maven with the biz.aQute.bnd:bnd-maven-plugin version 6.4.0 and have tried different approaches but with no success.

In my Maven dependencies I have the following ones defined:

<dependencies>
  <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
    </dependency>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <classifier>sources</classifier>
    </dependency>
</dependencies>

I've tried the following commands:

-includeresource: lib/guava.jar=guava-*.jar;lib:=true,\
  OSGI-OPT/src=@guava-sources.jar
-includeresource: lib/guava.jar=guava-*.jar;lib:=true,\
  OSGI-OPT/src=@guava-*-sources.jar
-includeresource: lib/guava.jar=guava-*.jar;lib:=true,\
  OSGI-OPT/guava-sources.jar=@guava-sources.jar;lib:=true,
-includeresource: lib/guava.jar=guava-*.jar;lib:=true,\
  OSGI-OPT/guava-sources.jar=guava-*-sources.jar;lib:=true,

Am I missing something?

pkriens commented 4 months ago

The syntax you used indicated the guava-*.jar was on the file system. In workspace bnd, you can use ${repo;com.google.guava:guava} instead of the file name to get it from a repository. I am not sure how this works in maven because their repository model is very different, maybe one of the maven users can chime in. @timothyjward ?

pkriens commented 3 months ago

Any feedback?

pkriens commented 3 months ago

please reopen if you want to take this further.