Dependencies from pom.xml not considered by Eclipse in Tycho Project

SpaceTrucker picture SpaceTrucker · Sep 18, 2012 · Viewed 11.4k times · Source

I created a Tycho project with an eclipse-plugin packaging. The project includes some dependencies that are specified via pom.xml. The relevant pom sections are:

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tycho.version>0.15.0</tycho.version>
</properties>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho.version}</version>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho.version}</version>
            <configuration>
                <pomDependencies>consider</pomDependencies>
                <environments>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>macosx</os>
                        <ws>cocoa</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>juno</id>
        <layout>p2</layout>
        <url>http://download.eclipse.org/releases/juno</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.release</id>
        <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/release</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.external</id>
        <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/external</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>com.springsource.org.testng</artifactId>
        <version>6.4.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guice</groupId>
        <artifactId>com.springsource.com.google.inject</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.aopalliance</groupId>
        <artifactId>com.springsource.org.aopalliance</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

And the Manifest is:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin-project-pure
Bundle-SymbolicName: plugin-project-pure
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.equinox.app,
 org.eclipse.uml2.uml;bundle-version="4.0.0",
 org.eclipse.uml2.uml.resources;bundle-version="4.0.0",
 org.junit;bundle-version="4.10.0",
 com.springsource.org.testng;bundle-version="[6.4.0,6.4.0]"

The project only consists of a class in the default package that uses an annotation from org.testng.annotations to test that during compilation the dependency is included.

If I'm building the project on the command line with Maven 3.0.4 everything works fine. After importing the project in Eclipse Juno, I get multiple errors. The most important one is in the manifest and it states that the bundle com.springsource.org.testng can't be resolved. There is also a compile error in the class, because the import of the annotation is not possible. The project has the Maven Nature configured. Am I missing something so that Eclipse Juno will also consider the dependencies of the pom?

Answer

oberlies picture oberlies · Sep 18, 2012

You can circumvent this problem splitting your project build into two parts:

  • First, aggregate your POM dependencies into a p2 repository. You'll need an eclipse-feature and an eclipse-repository module for this, plus a separate parent POM that lists the POM dependencies and configures pomDependencies=consider.
  • In the second build, add the p2 repository from the first build to the target platform, e.g. via a jar:file: URL pointing to the build result in your local Maven repository.

Then, you can also configure your target platform in Eclipse to include the p2 repository from the first build (which depends on how you currently configure it). You'll get the best consistency between Tycho and Eclipse if you use a so-called target definition file, which you can use both as target platform in Eclipse and in Tycho.

I am aware that all this is quite a bit of effort to set up, but AFAIK there are no better solutions that fully work.