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

From Eclipsepedia

< Tycho‎ | How Tos
Jump to: navigation, search
(deleted obviously outdated content; moved note about the transitivity problem into existing limitations entry)
m
Line 57: 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>

Revision as of 10:34, 30 October 2012

Contents

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.