5

I'm working on an Eclipse RCP + Maven project for the first time and I want to run some unit tests on my bundles with JUnit. It seems that the most recommended approach is to create a bundle fragment and use something like Tycho plugin to resolve dependencies. However, when I run mvn clean verify in my master pom, it should run the tests and deploy my application, but I'm get the following error instead:

[ERROR] Cannot resolve project dependencies:
[ERROR]   You requested to install 'myproject.app.feature.feature.group 1.0.0' but it could not be found
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-surefire-plugin:0.21.0:test (default-test) on project myproject.app.viewmanager-test: Execution default-test of goal org.eclipse.tycho:tycho-surefire-plugin:0.21.0:test failed: No solution found because the problem is unsatisfiable.: [Unable to satisfy dependency from tycho-extra-1408913392535 0.0.0.1408913392535 to myproject.app.feature.feature.group 1.0.0.; Unable to satisfy dependency from tycho-1408913392552 0.0.0.1408913392552 to myproject.app.feature.feature.group 1.0.0.; No solution found because the problem is unsatisfiable.] -> [Help 1]

I understand that Maven is failing to find 'myproject.app.feature.feature.group 1.0.0' but I don't know where it is getting this from because it seems that the name is wrong.

It might be worth to say that when I run the unit test inside Eclipse (not with Maven) it works.

This is the Tycho configuration in my test fragment:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>tycho-surefire-plugin</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <useUIHarness>true</useUIHarness>

        <dependencies>
            <dependency>
                <type>eclipse-feature</type>
                <artifactId>myproject.app.feature</artifactId>
                <version>1.0.0</version>
            </dependency>
        </dependencies>

    </configuration>
</plugin>

As suggested here, I'm adding the feature as a dependency because my test fragment requires some other bundles besides its host, so I was expecting this to work.

Any tips? The most similar issue I have found is this one, but both solutions didn't work for me.

Community
  • 1
  • 1
Fappaz
  • 3,033
  • 3
  • 28
  • 39
  • 1
    *I understand that Maven is failing to find 'myproject.app.feature.feature.group 1.0.0' but I don't know where it is getting this from because it seems that the name is wrong.* - Actually the name is correct, but this is hard to see. This error messages directly come from the p2 resolver, so they are on a very low abstraction level. For example the `.feature.group` suffix is p2's way to distinguish features from bundles. I've written a [wiki page](https://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting) to help understanding the error messages from p2. – oberlies Feb 27 '15 at 15:16

2 Answers2

4

Starting with Tycho 0.21.0, there is only limited support for declaring dependencies to reactor projects in the tycho-surefire-plugin: They only work if the test project already has some other dependency to the referenced reactor project. In your use case, where you add a dependency to a feature, this is not the case.

You could make the tycho-surefire-plugin dependencies configuration work again by adding a POM dependency to the feature project:

<dependencies>
   <dependency>
      <!-- Maven GAV of the feature project -->
      <groupId>myproject.groupId</groupId>
      <artifactId>myproject.app.feature</artifactId>
      <version>1.0.0-SNAPSHOT</version>
   </dependency>
</dependencies>

<build>
   <plugins>
      <plugin>
         <groupId>org.eclipse.tycho</groupId>
         <artifactId>tycho-surefire-plugin</artifactId>
         <version>${tycho-version}</version>
         <configuration>
            <dependencies>
               <dependency>
                  <type>eclipse-feature</type>
                  <artifactId>myproject.app.feature</artifactId>
                  <version>1.0.0</version>
               </dependency>
            </dependencies>
         </configuration>
      </plugin>
   </plugins>
</build>

However the recommended way to specify extra test dependencies is to do this in the target-platform-configuration instead of on the tycho-surefire-plugin:

<plugin>
   <groupId>org.eclipse.tycho</groupId>
   <artifactId>target-platform-configuration</artifactId>
   <configuration>
      <dependency-resolution>
         <extraRequirements>
            <requirement>
               <type>eclipse-feature</type>
               <id>myproject.app.feature</id>
               <versionRange>1.0.0</versionRange>
            </requirement>
         </extraRequirements>
      </dependency-resolution>
   </configuration>
</plugin>

Note: The element names to specify dependencies are different in the target-platform-configuration compared to the tycho-surefire-plugin. So when migrating your configuration, you need to adapt the tag names:

  • <type> (unchanged)
  • <artifactId><id>
  • <version><versionRange>

Remark: Although the tag names are different, the semantics of the elements are the same: So even though the old name was <version>, the value was always interpreted as a version range. A version range that consists of a single version like 1.0.0 stands for for a version range without upper bound, i.e. version 1.0.0 or later.

oberlies
  • 11,503
  • 4
  • 63
  • 110
  • Thanks for the tip. I started using the target-platform-configuration and it solved the problem with non-GUI test fragments. Good to know that this is the recommended way. – Fappaz Sep 25 '14 at 21:15
1

I just had essentially the same problem. It seems that with tycho 0.21 dependencies have to be added using the target-platform-configuration plugin. See tycho bug 436617 comment #11 for an example.

Lutz Wrage
  • 46
  • 4
  • Great, that solved a big part of my problem. However, some test fragments are complaining about missing packages from JavaFX, even if they are declared in my target platform and feature. That's another subject though. Thanks. – Fappaz Sep 15 '14 at 02:04