Tycho无法解析tycho-surefire-plugin中配置的依赖项

时间:2014-08-24 21:41:56

标签: maven junit eclipse-rcp tycho tycho-surefire-plugin

我第一次在Eclipse RCP + Maven项目上工作,我想在JUnit的捆绑包上运行一些单元测试。似乎最推荐的方法是创建一个bundle片段并使用类似Tycho插件的东西来解决依赖关系。但是,当我在我的主pom中运行mvn clean verify时,它应该运行测试并部署我的应用程序,但我收到了以下错误:

[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]

我知道Maven未能找到myproject.app.feature.feature.group 1.0.0'但我不知道从哪里得到这个,因为看起来这个名字是错的。

值得一提的是,当我在Eclipse中运行单元测试时(不是使用Maven),它可以工作。

这是我的测试片段中的Tycho配置:

<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>

根据建议here,我将该功能添加为依赖项,因为我的测试片段除了主机之外还需要其他一些捆绑包,所以我希望这可以工作。

任何提示?我发现的最相似的问题是this one,但这两种解决方案对我都没有用。

2 个答案:

答案 0 :(得分:4)

从Tycho 0.21.0开始,在tycho-surefire-plugin中声明对reactor项目的依赖性的支持有限:它们仅在测试项目已经对引用的reactor项目具有其他依赖性时才起作用。在您的用例中,向功能添加依赖项,情况并非如此。

可以通过向功能项目添加POM依赖项来使tycho-surefire-plugin依赖项配置再次起作用:

<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>

然而,推荐指定额外测试依赖项的方法是在target-platform-configuration而不是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>

注意:与tycho-surefire-plugin相比,target-platform-configuration中指定依赖项的元素名称不同。因此,在迁移配置时,您需要调整标记名称:

  • <type>(未更改)
  • <artifactId><id>
  • <version><versionRange>

备注:虽然标记名称不同,但元素的语义是相同的:因此,即使旧名称为<version>,该值也始终被解释为版本范围。由1.0.0之类的单个版本组成的版本范围代表没有上限的版本范围,即版本1.0.0或更高版本。

答案 1 :(得分:1)

我刚才遇到了同样的问题。看来tycho 0.21必须使用target-platform-configuration插件添加依赖项。有关示例,请参阅tycho bug 436617 comment #11

相关问题