1

In a Tycho build OSGi dependencies are usually specified in the MANIFEST.MF of the respective modules (e.g., Eclipse plugins). As far as I understand, Tycho identifies those dependencies, resolves them and adds them to the maven build model at build time (sorry for the wayback machine link; the Tycho site seems to undergo some changes right at the moment).

Is it possible to reference such a derived dependency in other maven plugins? For example, if I want to copy particular dependencies with maven-dependency-plugin how would I get to know which groupId, artifactId and version I would have to provide?

Johnson
  • 306
  • 1
  • 15

1 Answers1

1

Tycho has its own dependency resolution mechanism which is different from Maven's. Tycho loads dependencies defined in the Manifest from p2 repositories and not from Maven repositories (at least usually*). Maven artifacts and p2 bundles have different meta-data structures so you can't always map them to each other. For example bundles don't have the concept of group/artifact ID.

Regular Maven plugins can only handle regular Maven dependencies. p2 artifacts are not visible to them.

Depending on what you are trying to achieve, you could try to convert p2 bundles to Maven dependencies first, and then process them with Maven plugins. For your specific example this might help, if you don't mind splitting the build into multiple steps: Use dependencies from Eclipse p2 repository in a regular Maven build?

* You can configure Tycho with pomDependencies=consider to include Maven artifacts. Those would be visible to regular Maven plugins, but I would not recommend doing that, it makes building/deploying harder the more complex the build gets

kapex
  • 28,903
  • 6
  • 107
  • 121
  • Just to clarify, I am aware of the first paragraph of your answer. I thought, however, Tycho still needs to represent the OSGi dependencies in the Maven way at runtime somehow. And as such, artifactID, groupID and version might be chosen by some deterministic rules for this runtime representation. And if I knew the rules, I could probably reference the OSGi dependencies although they are not statically available as true Maven artifacts. Unfortunately, I don't know anything about the runtime model of Maven so I might have a completely wrong expectation of what is going on. – Johnson Oct 27 '20 at 11:49
  • To my understanding Tycho doesn't represent OSGi dependencies in a way that Maven understands natively. From the perspective of Maven and regular Maven plugins, the build consists of modules without any (Maven) dependencies. You certainly can convert OSGi bundles to Maven artifacts by some rules. If the the bundles have been build with Maven and contain a pom it just get the group/artifact ID from there. I guess you could export the bundles then and process them in another build. – kapex Oct 27 '20 at 12:52
  • I'm not sure why one would want/need to do that though. Do you have a specific use case? Usually people want to do the other way around and convert maven artifacts to bundles for their builds, there are a few plugins and tools for that. – kapex Oct 27 '20 at 12:53
  • 1
    The original scenario which brought up the idea of referencing OSGi bundles is flawed from an architectural point of view so my idea was more a hack than a good solution. It's best to not go into detail here as I don't want to pollute the hopefully rather clear question with a discussion about alternatives. As long as noone else proves the opposite, I will take your answer as granted :) – Johnson Oct 27 '20 at 13:56
  • Kind of related to this topic, I saw Tycho 2.1 now has support for automatically converting non-OSGi Maven artifacts to bundles when using pomDependencies=consider. They use deterministic rules to create OSGi meta data (e.g. group and artifact id is combined to generate the bundle id). That means it should be easier to have builds with only Maven dependencies and no p2 repositories. In those build all dependencies would be visible to regular Maven plugins. – kapex Nov 23 '20 at 20:27
  • True, but that's the other way round, right? Although I never used it myself, I think that approach was already supported before by other plugins based on BND. That was more or less my motivation for this question. I thought if there are deterministic rules for one direction of the mapping between artifact-meta-data and bundle-meta-data there would also be a natural mapping in the opposite direction. – Johnson Nov 25 '20 at 10:49
  • Yeah it's the other way around. I think internally Tycho uses BND for that too. You can generate OSGi metadata for any Maven artifact but you can't always calculate Maven meta data from OSGi bundles. The more important part is that with the new improvements of pomDependencies=consider, builds with only maven dependencies became more feasible. You wouldn't need to calculate anything in the opposite direction if all your dependencies come from Maven, because in that case Maven artifactIds and groupids are already known. – kapex Nov 25 '20 at 11:09
  • 1
    Most dependencies in the Eclipse world, however, might still only be available as OSGI bundles. Which does not allow to fully consider them in all Maven plugins (f.e., define inclusions/exclusions for them in maven-dependency-plugin). – Johnson Nov 26 '20 at 12:35