我第一次在Eclipse + Maven项目上工作,我想用JUnit在我的包上运行一些单元测试。似乎最推荐的方法是创建一个包片段,并使用类似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>正如建议的这里一样,我将这个特性作为依赖项添加,因为我的测试片段除了它的主机之外还需要一些其他的包,所以我希望它能工作。
有小费吗?我发现的最相似的问题是这一个,但这两种解决方案对我都不起作用。
发布于 2014-09-25 12:14:00
从Tycho 0.21.0开始,只有有限的支持声明依赖于tycho-surefire-plugin中的反应堆项目:只有当测试项目已经对所引用的反应堆项目有一些其他依赖时,它们才能工作。在您的用例中,向特性添加依赖项时,情况并非如此。
可以通过向特性项目添加POM依赖项,使tycho-插件依赖项配置再次工作:
<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 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或更高版本。
发布于 2014-08-26 19:33:23
我只是遇到了同样的问题。看起来,对于tycho 0.21,必须使用目标平台配置插件来添加依赖项。有关示例,请参见tycho 436617评论#11。
https://stackoverflow.com/questions/25476595
复制相似问题