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

标签 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)运行单元测试时,它可以工作。

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

<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 ,但这两种解决方案都不适合我。

最佳答案

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

但是,推荐指定额外测试依赖项的方法是在目标平台配置中而不是在 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 相比,目标平台配置中指定依赖项的元素名称不同。因此,在迁移配置时,您需要调整标签名称:

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

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

关于maven - Tycho 无法解析 tycho-surefire-plugin 中配置的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25476595/

相关文章:

java - Jersey 客户端将数据发送到 String

java - 使用 WSDL 和 codehaus jaxb2 的 Spring Soap Web 服务客户端;需要 XmlRootElement 吗?

Maven 中央存储库 Artifact 源代码/项目 URL/许可证标识

java - 在 docker build 阶段使用本地 m2 仓库

java - Eclipse RCP : How to Edit or Delete the "Editor Area" view in helloworld app

java - 在桌面应用程序上外部化数据库配置的最佳方法是什么?

java - Eclipse 4 应用程序不显示我的 View

java - spring 3.12用的是cglib 2.2.2,spark 8.0用的是cglib 3.0,但是需要同时执行?

json - 预期返回 JSON 的单元测试方法示例

java - 通过所有 SpringBootTests 使用一个 spring boot 上下文