Skip to main content
Jump to: navigation, search

Difference between revisions of "Tycho/How Tos/Dependency on pom-first artifacts"

< Tycho‎ | How Tos
(striked out incorrect sentence -> see http://wiki.eclipse.org/Tycho/Target_Platform#.22POM_dependencies_consider.22)
 
(6 intermediate revisions by 5 users not shown)
Line 6: Line 6:
 
</pre>
 
</pre>
  
Demo application itp02 consist of two parts, <tt>build01</tt> and <tt>build02</tt>.
+
Demo application itp02 consist of two parts, <tt>[http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp02/build01 build01]</tt> and <tt>[http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp02/build02 build02]</tt>.
  
 
=== build01 ===
 
=== build01 ===
Line 12: Line 12:
 
First part (i.e. <tt>build01</tt>) is a simple project that uses maven-bundle-plugin to generate OSGi bundle manifest.
 
First part (i.e. <tt>build01</tt>) is a simple project that uses maven-bundle-plugin to generate OSGi bundle manifest.
  
<tt>pomfirst-bundle</tt> is a simple project with packaging=jar that uses maven-bundle-plugin:manifest goal to generate bundle manifest based on sources of the project and their external dependencies, plexus-utils in this particular example.
+
<tt>[http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp02/build01/pomfirst-bundle pomfirst-bundle]</tt> is a simple project with packaging=jar that uses maven-bundle-plugin:manifest goal to generate bundle manifest based on sources of the project and their external dependencies, plexus-utils in this particular example.
  
<tt>pomfirst-thirdparty</tt> does not have any sources itself, but "wraps" thirdparty library available from maven repository in an OSGi bundle.
+
<tt>[http://git.eclipse.org/c/tycho/org.eclipse.tycho-demo.git/tree/itp02/build01/pomfirst-thirdparty pomfirst-thirdparty]</tt> does not have any sources itself, but "wraps" thirdparty library available from maven repository in an OSGi bundle.
  
 
You can read more about maven-bundle-plugin [http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html here], but important point to note, this is not a tycho project. Artifacts installed into local repository have correct OSGi bundle manifest, but does not have any tycho or p2 specific information.
 
You can read more about maven-bundle-plugin [http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html here], but important point to note, this is not a tycho project. Artifacts installed into local repository have correct OSGi bundle manifest, but does not have any tycho or p2 specific information.
Line 45: Line 45:
  
 
First, there is dependency on the pom-first project
 
First, there is dependency on the pom-first project
<strike>'''Note''': The dependencies that the target platform will consider are the ones defined in the pom.xml that specifies the target-platform-configuration. 
 
Your bundles should not have any Maven dependencies since OSGi dependencies are specified Manifest-First in MANIFEST.MF as Import-Package (or Require-Bundle).</strike>
 
  
 
<source lang="xml">
 
<source lang="xml">
Line 59: Line 57:
 
<source lang="xml">
 
<source lang="xml">
 
<plugin>
 
<plugin>
<groupId>org.sonatype.tycho</groupId>
+
<groupId>org.eclipse.tycho</groupId>
 
<artifactId>target-platform-configuration</artifactId>
 
<artifactId>target-platform-configuration</artifactId>
 
<version>${tycho-version}</version>
 
<version>${tycho-version}</version>
 
<configuration>
 
<configuration>
<resolver>p2</resolver>
 
 
<pomDependencies>consider</pomDependencies>
 
<pomDependencies>consider</pomDependencies>
 
</configuration>
 
</configuration>
Line 71: Line 68:
 
pomDependencies=consider tells tycho target platform resolver (p2-based in this example) to ''consider'' <dependencies/> element. In case of p2-based TP resolver, this is a multistep process
 
pomDependencies=consider tells tycho target platform resolver (p2-based in this example) to ''consider'' <dependencies/> element. In case of p2-based TP resolver, this is a multistep process
  
# p2 metadata is generated for all maven dependencies. Currently this only works for OSGi bundles, all other depenedncies are silently ignored.
+
# p2 metadata is generated for all maven dependencies. Currently this only works for OSGi bundles, all other dependencies are silently ignored.
 
# generated p2 metadata is merged with p2 metadata from configured local and remote repositories
 
# generated p2 metadata is merged with p2 metadata from configured local and remote repositories
 
# p2 resolver is invoked to calculate project build target platform, i.e. transitive set of dependencies
 
# p2 resolver is invoked to calculate project build target platform, i.e. transitive set of dependencies
 
# finally, equinox resolver is used to resolve actual project dependencies using set of bundles from build target platform
 
# finally, equinox resolver is used to resolve actual project dependencies using set of bundles from build target platform
 
== Importing in m2e 0.13.0 ==
 
 
Starting with version 0.5.0-SNAPSHOT, m2eclipse-tycho has been extended to provide limited interoperability between Tycho manifest-first and maven-bundle-plugin pom-first projects, including experimental support for "wrapper" bundles that embed thirdparty dependencies using <Embed-Dependency> instructions.
 
 
Download Eclipse 3.7 RC1 or newer "Classic" distribution from http://eclipse.org/downloads/. Then install m2e 0.13.0 RC1 or newer from Indigo p2 repository.
 
 
Using m2e standard "Existing Maven Project" import wizard, select <tt>itp02</tt> directory (i.e. the parent directory of <tt>build01</tt> and <tt>build02</tt>).
 
 
M2E is expected to find all pom-first and manifest-first projects and automatically offer installation of m2eclipse-tycho from m2e marketplace
 
[[Image:Import Maven Projects 001.png|border]]
 
 
Allow installation of m2eclipse-tycho and confirm workspace restart when prompted.
 
 
Upon workspace restart, m2e is expected to automatically complete project configuration and it should be possible to successfully run <tt>tycho.demo.itp02.bundle.tests</tt> as JUnit Plug-In Test from IDE.
 
 
{| border="1"
 
| [[Image:Information icon.png]]
 
| Due to a bug in m2eclipse-tycho or PDE, <tt>tycho.demo.itp02.bundle</tt> and <tt>tycho.demo.itp02.bundle.tests</tt> sometimes have compilation errors after import. Although we are not able to reproduce the problem reliably, the following workaround appears to work
 
 
* select all workspace projects, right-click, Maven, Update Project Configuration.
 
* clean build all workspace projects
 
|}
 
 
 
 
  
 
== Limitations ==
 
== Limitations ==
Line 120: Line 91:
 
Currently, ProjectC build will fail because pom-first are not transitive.
 
Currently, ProjectC build will fail because pom-first are not transitive.
  
Workaround is to add pom-first dependency on ProjectA to ProjectC. It is likely Nexus/Pro OSGi support will provide more elegant solution to this problem sometime in the future.
+
Workaround is to add pom-first dependency on ProjectC to ProjectA. If projectB and projectC share a common parent POM, one would typically add the POM dependencies to projectA in that parent POM.
 +
 
 +
=== Tycho target-platform-configuration/pomDependencies=consider is restricted to packaging=jar ===
 +
 
 +
If You split up Your project structure like above into build01 and build02. Then Your build01 packaging type must be 'jar' (not 'bundle'). If You use 'bundle' cannot build02 detect the JAR. And the build02 fails.  
  
=== Local target platform resolver (i.e. -Dtycho.targetPlatform=...) ignores pomDependencies=consider ===
+
* that`s strange.
 +
* it seems that tycho 'target-platform-configuration' looks into the installed '~/.m2/...build01/..-pom.xml
 +
* and interpete the packaging type
  
No good excuses here and it should be fairly straightforward to implement. (this may have been added in 0.9.0, but the committer unfortunately did not provide integration test(s), so I can't tell for sure)
+
Than You cannot use the full power of 'maven-bundle-plugin'.
  
 
[[Category:Tycho|Dependency on pom-first artifacts]][[Category:Tycho/How To|Dependency on pom-first artifacts]]
 
[[Category:Tycho|Dependency on pom-first artifacts]][[Category:Tycho/How To|Dependency on pom-first artifacts]]

Latest revision as of 07:04, 3 August 2017

Demo application

  • Checkout demo application
git clone http://git.eclipse.org/gitroot/tycho/org.eclipse.tycho-demo.git

Demo application itp02 consist of two parts, build01 and build02.

build01

First part (i.e. build01) is a simple project that uses maven-bundle-plugin to generate OSGi bundle manifest.

pomfirst-bundle is a simple project with packaging=jar that uses maven-bundle-plugin:manifest goal to generate bundle manifest based on sources of the project and their external dependencies, plexus-utils in this particular example.

pomfirst-thirdparty does not have any sources itself, but "wraps" thirdparty library available from maven repository in an OSGi bundle.

You can read more about maven-bundle-plugin here, but important point to note, this is not a tycho project. Artifacts installed into local repository have correct OSGi bundle manifest, but does not have any tycho or p2 specific information.

build02

Second part (i.e. build02) is a multi-module tycho project. tycho.demo.itp02.bundle is eclipse-plugin project which depends on pom-first project via Import-Package: tycho.demo.itp02.pomfirst in bundle manifest. tycho.demo.itp02.bundle.tests is a simple junit4 test project.

Building from command line

  • Build pom-first project
cd itp02/build01/pomfirst-bundle
MAVEN_HOME/bin/mvn clean install

This will build and install tycho.demo.itp02:pomfirst-bundle:1.0.0-SNAPSHOT into Maven local repository. The build is expected to succeed.

  • Build tycho project
cd ../../build02
MAVEN_HOME/bin/mvn clean install

This will build both build02 modules and the build is expected to succeed.

What happens under the hood

There are two "interesting" elements in build02/pom.xml.

First, there is dependency on the pom-first project

<dependency>
<groupId>tycho.demo.itp02</groupId>
<artifactId>pomfirst-bundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>

Second, there is pomDependencies target platform configuration parameter.

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>

pomDependencies=consider tells tycho target platform resolver (p2-based in this example) to consider <dependencies/> element. In case of p2-based TP resolver, this is a multistep process

  1. p2 metadata is generated for all maven dependencies. Currently this only works for OSGi bundles, all other dependencies are silently ignored.
  2. generated p2 metadata is merged with p2 metadata from configured local and remote repositories
  3. p2 resolver is invoked to calculate project build target platform, i.e. transitive set of dependencies
  4. finally, equinox resolver is used to resolve actual project dependencies using set of bundles from build target platform

Limitations

It is not possible to mix pom-first and manifest-first projects in the same reactor build.

Dependency resolution happens very early during maven build, before execution of build lifecycle of any project and well before bundle manifests can be generated for pom-first projects. To resolve dependencies of manifest-first projects, however, Tycho needs to to read bundle manifests of all pom-first artifacts.

This limitation cannot be relaxed without fundamental changes to Maven build lifecycle. Currently, the only solution is to build pom-first projects separately, before building manifest-first projects.

Pom-first dependencies of manifest-first projects are not fully transitive

Consider the following related projects, all built separately

  • ProjectA, is a pom-first project with regular maven dependencies.
  • ProjectB, is a manifest-first project with pom-first dependency on ProjectA
  • ProjectC, is a manifest-first project with regular OSGi dependency on ProjectB

Currently, ProjectC build will fail because pom-first are not transitive.

Workaround is to add pom-first dependency on ProjectC to ProjectA. If projectB and projectC share a common parent POM, one would typically add the POM dependencies to projectA in that parent POM.

Tycho target-platform-configuration/pomDependencies=consider is restricted to packaging=jar

If You split up Your project structure like above into build01 and build02. Then Your build01 packaging type must be 'jar' (not 'bundle'). If You use 'bundle' cannot build02 detect the JAR. And the build02 fails.

  • that`s strange.
  • it seems that tycho 'target-platform-configuration' looks into the installed '~/.m2/...build01/..-pom.xml
  • and interpete the packaging type

Than You cannot use the full power of 'maven-bundle-plugin'.

Back to the top