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

Fer*_*Paz 5 junit eclipse-rcp tycho maven tycho-surefire-plugin

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

[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]
Run Code Online (Sandbox Code Playgroud)

我知道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>
Run Code Online (Sandbox Code Playgroud)

正如这里所建议的那样,我将该功能添加为依赖项,因为我的测试片段除了它的主机之外还需要一些其他的包,所以我希望这可以工作.

有小费吗?我发现的最相似的问题是这个问题,但这两个解决方案对我都不起作用.

obe*_*ies 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>
Run Code Online (Sandbox Code Playgroud)

然而,指定额外测试依赖项的推荐方法是在目标平台配置中而不是在 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>
Run Code Online (Sandbox Code Playgroud)

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

  • <type>(不变)
  • <artifactId><id>
  • <version><versionRange>

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