title: Building a p2 repository by resolving Tycho features from a Maven repository
body: <p>I'm trying to build a p2 repository from Tycho feature artifacts which are deployed in a remote Maven repository, without having to install the artifacts into the local Maven repository first (as in <a href="https://stackoverflow.com/questions/7345708/tycho-cant-resolve-eclipse-feature-of-another-reactor-build">Tycho fails to resolve reference from product to eclipse-feature from a different reactor build</a>), and without having to build all features and the repository together in a single reactor build.</p>
  
  <p><strong>Background</strong></p>
  
  <p>I have a multi-module Tycho project that builds several Eclipse plugins and features.</p>
  
  <p>So that I can build each module separately - and so that I can reference OSGI artifacts in our Nexus Maven repository - I have enabled <code>&lt;pomDependencies&gt;consider&lt;/pomDependencies&gt;</code> in my target platform, and added Maven dependencies between the modules or to the repository artifacts as usual with <code>&lt;dependency/&gt;</code> elements.</p>
  
  <p>This works well - I can build the features or run the plugin tests without their dependant plugins being either in my local Maven repository or in the same reactor build. For example, when I run <code>mvn test</code> on a plugin test project, the relevant dependencies will be downloaded from Nexus and Tycho will happily resolve the <code>Import-Package</code>s in my manifest against these, build everything and run the tests. So far so good.</p>
  
  <p>I would like to generate a p2 repository from these features so that I can install them in Eclipse from an update site, and the advertised way to do this is with the <code>eclipse-repository</code> packaging type. But here the plan falls down - Tycho doesn't seem to be able to resolve feature dependencies when building repositories in the same way as it can resolve plugin dependencies when building features. All attempts yield:</p>
  
  <pre><code>[ERROR] Cannot resolve project dependencies:
  [ERROR]   Software being installed: my.eclipse.repository raw:0.0.1.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.0.1-SNAPSHOT
  [ERROR]   Missing requirement: my.eclipse.repository raw:0.0.1.'SNAPSHOT'/format(n[.n=0;[.n=0;[-S]]]):0.0.1-SNAPSHOT requires 'my.prj.eclipse.project.feature.feature.group 0.0.0' but it could not be found
  </code></pre>
  
  <p>There are two ways I have successfully built the p2 repository:</p>
  
  <ul>
  <li><strong>As part of the same reactor build</strong>. If I make the <code>eclipse-repository</code> a module within the Tycho multi-module project, and build the whole project at once with e.g. <code>mvn verify</code>, the features are resolved fine. But I don't want to do this. I would prefer to build modules individually. This means our CI can have an indicator for each module, and we can immediately see what module tests have failed in; it gives us opportunities for parallelising builds; and we avoid having to be constantly running builds on modules that haven't changed. It would be a shame to have to use a monolithic Maven build.</li>
  <li><strong>If I install the Tycho project into my local Maven repository</strong>, by running <code>mvn install</code> on the dependency. But I don't want to do this either, because this would mean the build is inherently irreproducable, as it would be sensitive to the state of the local repository. Our CI is currently set up to maintain a Maven repository per job and to completely wipe it at the start of execution, to shield us from this potential messiness.</li>
  </ul>
  
  <p>So my question is: is there a third way? Is there any way I can get the Tycho plugin responsible for building <code>eclipse-repository</code> packaging types to download features from a remote Maven repository? Or any other way I can build the p2 repository from plugins that have been individually built and deployed to the Maven repository?</p>
  
  <p>Things I've tried include:</p>
  
  <ul>
  <li>specifiying the Maven feature depedencies as both <code>jar</code> and <code>eclipse-feature</code></li>
  <li><p>explicitly adding the features to the target platform, like</p>
  
  <p><code>...
  &lt;artifactId&gt;target-platform-configuration&lt;/artifactId&gt;
  &lt;version&gt;${tycho.version}&lt;/version&gt;
  &lt;configuration&gt;
     &lt;dependency-resolution&gt;
        &lt;extraRequirements&gt;
           &lt;requirement&gt;
              &lt;type&gt;eclipse-feature&lt;/type&gt;
              &lt;id&gt;my.prj.eclipse.project.feature&lt;/id&gt;
              &lt;versionRange&gt;0.0.0&lt;/versionRange&gt;
           &lt;/requirement&gt;
           ...</code></p></li>
  </ul>
  
  <hr>
  
  <p>The <strong>closest</strong> thing I've found to a decent solution is have a multi-module Tycho project that just contains the repository and features.</p>
  
  <pre><code>feature-project
   |- feature1    (eclipse-feature)
   |- feature2    (eclipse-feature)
   |- repository  (eclipse-repository)
  </code></pre>
  
  <p>Building this <strong>works</strong> - all plugins added to the top-level POM are downloaded from Nexus, available for inclusion in each feature and included in the generated repository.</p>
  
  <p>However this is far from ideal because I can no longer store my features logically alongside my plugins; they need to be in separate project hierarchies. Attempting to build the features and repository separately, like with <code>mvn clean verify -pl :feature1,feature2,repository</code>, fails presumably due to <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=380152" rel="nofollow noreferrer">Bug 380152</a>.</p>
  
  <p>Is there a better way? Any help would be gratefully received.</p>
  
  <p>Many thanks</p>
  
  <hr>
  
  <p>(As an aside: building the repository with <code>mvn clean verify -Dtycho.localArtifacts=ignore</code> will <strong>succeed</strong> if the features are present in the local Maven repository, and won't show you the warning that artifacts are being resolved from the local repo... is this a bug?)</p>