Question

I am trying to create an Eclipse based setup where Eclipse projects are Maven based. So it should all work with Maven whether or not Eclipse is used.

I have a dependencies on various Eclipse project libraries, with more to be added. I want to use p2 repositories, and I've managed to pull an Eclipse EMF library and turn it into a jar following this example: Use dependencies from Eclipse p2 repository in a regular Maven build?

The problem is, I could not find a way of streamlining the process. I'd need to manually install the re-packaged dependency from the question given above to local Maven repository so that I can reference that in other projects. I'd like to seamlessly integrate artefacts from p2 repositories to my Maven based setup. m4e does not look like the smooth solution I'm looking for: Ideally I'd like to distribute a set of directories which would do everything in response to a simple mvn clean install : pull libraries from p2 repo, pull other libraries from Maven repositories etc..

Is this doable via Maven and Tycho integration?

Update: first, clarification to the question: just being able to reference to P2 repositories does not help with the scenario where this reference needs to be used from another project. The library (or libraries) referenced from P2 repository must be re-packaged as a jar so that it can be referenced by other Maven projects. The referenced question does the packaging. However, it does not explain how this repackaged output (assembly) can be used from other projects. In my case, this turned out to be referencing the assembly from an aggregating POM, and inheriting form that POM for all projects that would like to use the library with the P2 repository origin.

Was it helpful?

Solution 2

The solution is to create a multi module setup with Maven, and declare a dependency on the outputs of EMF library re-packaging (from the question I've referenced) The parent pom for all projects has this:

    <dependencies>
    <dependency>
        <groupId>com.mymodule</groupId>
        <artifactId>myartifact</artifactId>
        <version>0.0.1</version>
        <classifier>repackaged</classifier>                 
    </dependency>
  </dependencies>
      <modules>
            <module>../mymodule</module>
     </modules>

Which lets all modules that has this module as parents access the repackaged P2 artifacts.

OTHER TIPS

Tycho projects can pull their dependencies from both p2 repositories and Maven repositories (see this related answer). This could be a solution for you, even if you are not building for an OSGi runtime: Most OSGi bundles also work as "plain" JARs on the classpath.

Limitation: The artifacts referenced from Maven repositories also have to be OSGi bundles, so that Tycho considers them for dependency resolution. If this is not the case (and you can't find replacements which are OSGi bundles), you may be able to combine Tycho's dependency resolution with plain Maven plug-ins:

  • Use one of Tycho's packaging types (e.g. eclipse-feature) and specify the dependencies to the p2 artifacts in the file format for the packaging type (e.g. a feature.xml)
  • Additionally configure the plain Maven goals in your POM. Tycho injects the OSGi/p2 dependencies into the Maven model at runtime, so for example a maven-compiler-plugin:compile call would see both the Maven dependencies and the p2 dependencies.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top