Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tycho resolves the wrong version of my own manifest-first artifacts

Tags:

maven

tycho

Consider the following scenario: My application has some dependencies on my own POM-first artifacts (built with pure Maven) and some dependencies on my own manifest-first artifacts (built with Tycho). For the POM-first artifacts, Tycho resolves the exact the version I specified in the POM. For the manifest-first artifacts, Tycho resolves the locally built units which may have a higher version.

In my concrete case, I specified a dependency in the pom.xml to the manifest-first artifact in version 1.2.0, but I get warning "The following locally built units have been used to resolve project dependencies" with version 1.3.0.2012xxx.

I have already found following bugs and discussions, but I don't understand why there is a difference in Tycho resolving POM-first and manifest-first dependencies.

  • https://bugs.eclipse.org/bugs/show_bug.cgi?id=355367
  • http://dev.eclipse.org/mhonarc/lists/tycho-user/msg01673.html
like image 961
howlibird Avatar asked Sep 10 '12 10:09

howlibird


2 Answers

For those interested to force tycho to ignore local artifacts when resolving the target platform, add the CLI tycho.localArtifacts=ignore as in e.g.

mvn clean install -Dtycho.localArtifacts=ignore

More details can be found on the Tycho-Target Eclipse Wiki

like image 34
Georgios Stathis Avatar answered Nov 24 '22 17:11

Georgios Stathis


Dependency-resolution is a two-step process in Tycho:

  • First, Tycho computes the so-called target platform, which is the set of artifacts that are considered for dependency resolution. In this step, Tycho evaluates the POM dependencies according to the Maven rules and adds the result to the target platform. Also, all Tycho artifacts you have built locally with mvn install are added to the target platform.

  • Then, Tycho resolves your project's dependencies (from the MANIFEST.MF, feature.xml, etc.) according to the OSGi rules. Unlike in Maven dependencies, OSGi dependencies are typically specified as version ranges. So if you write

    Require-Bundle: my.bundle;bundle-version="1.2.0"  
    

    you are saying that you want version 1.2.0 or later. You typically don't want to specify an exact version here, because this would have implications on the runtime. But you do want to control what happens at build time, which is why there are various ways to control the content of the target platform.

In your particular case, you have your POM-first artifacts in the target platform in the version specified in the POM. Then, you also seem to be specifying a POM dependency to your Tycho artifacts (which is uncommon, but okay), so you will have the Tycho artifacts in the specified version in the target platform. But since you have also built a newer version of the Tycho artifacts locally with mvn install, these will also be in the target platform. The dependency resolution (step 2) hence has a choice between two versions, an will typically pick the later version.

To prevent the locally built artifacts from being added to the target platform, you can delete the file ~/.m2/repository/.meta/p2-local-metadata.properties. (I'm assuming you already know this, but just to be sure. Bug 355367 will also bring a alternative, more convenient option in 0.16.0.)

And now I finally get to your question why the behaviour is different for POM-first artifacts compared to Tycho artifacts:

  • Assume multiple Tycho artifacts are built together in the same reactor. Then each artifact can use the other artifacts as dependencies without needing any specific target platform configuration, e.g. you don't need POM dependencies to the artifacts in the same reactor. (Or in other words: upstream artifacts from the same reactor are automatically part of a module's target platform.) So in order to support re-builds of parts of a Tycho reactor (after a mvn install of the full reactor), locally installed Tycho artifacts need to be added to every module's target platform. Tycho can't know if they were originally part of the same reactor, so it just adds them all.

  • For POM-first artifacts, the reference to the artifact is always there (through the Maven configuration inheritance), even if only a part of a Tycho reactor is built. Therefore there doesn't need to be any mechanism for picking up any version of the locally built POM-first artifacts, but Tycho can add the exactly specified version to the target platform.

like image 157
oberlies Avatar answered Nov 24 '22 17:11

oberlies