如何在 tycho 中引用 mockito?

时间:2023-05-02
本文介绍了如何在 tycho 中引用 mockito?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我目前正在尝试让 tycho 完成我的构建(约 30 个捆绑包).
在我的单元测试中使用 的说明.(我不确定您是否需要指定解析器).

关于 Nexus 中对 p2 存储库的支持,我的理解是 Nexus 的 p2 插件已经开源:

  • Nexus - P2 存储库插件
  • Nexus - Bundle Maker
  • nexus-p2-repository-plugin 的 Github 存储库

I'm currently trying to get my build (~30 bundles) done by tycho.
I faced some confusing problems when using Mockito in my unit tests.
I created an eclipse-test-plugin as fragment project to the tested bundle. Since tycho should resolve the required bundles using the manifest, I removed the dependency to mockito from the pom.xml.
When I then try to add mockito to the required bundles in the manifest mockito isn't listed. I found this post and created a target platform pointing to eclipse indigo.
I included the platform specifics so I don't need the eclipse delta pack. Then the first strange thing occurs. Eclipse is telling me that there are some unsatisfiably dependencies and when I set the newly created target platform as active within eclipse, no more packages like org.osgi.framework, etc. can be resolved by eclipse. But when I build an eclipse-product using tycho and the target platform it is working.

If I set the current eclipse installation as active platform the bundles are resolved. I've selected the following of the indigo release:

  • Eclipse RCP Plug-in Developer Resources
  • Equinox Target Components
  • Jetty Target Components

So my first question is "What is wrong with my target-platform so that tycho is able to use it but eclipse isn't?"

To get closer to my original problem (getting mockito running) I set the current eclipse installation as the active target platform. Eclipse then can resolve the org.osgi.framework package and others.
I added then the previously removed dependency to mockito again to my pom.xml like in the above-mentioned post. But I still can't find mockito when I try to add it to the required bundles in the manifest.

So my second question is "What am I doing wrong? How do you reference bundles that are not published at the eclipse update site, e.g. the maven central repository?"

Update: During my research I found two ways of including bundles from non-p2-update-sites in my target-platform:

  1. Nexus Pro
    The professional version of Nexus supports p2-Proxy repositories which can wrap default maven repositories like the Maven Central Repository into a p2 update-site, but the professional version costs round about $800 per year.
  2. Create an eclipse-repository
    You can create a new maven project with packaging eclipse-repository including all your desired bundles. The created artifact is then deployed to a common web server.

In your target-platform you can then reference the Nexus p2-proxy repo or the web hosted p2-repo.
Does anyone know other ways - probably more convenient/less expensive?

Please help me understand the confusing world of tycho a bit more...
Thanks in advance

解决方案

If mockito isn't in your target platform (and you don't have it in a p2 repository), the easiest thing to do is probably to re-add the dependency back into your pom (without removing the mockito import from your manifest).

I think you'll also need to specify the following in the pom, in the configuration for the target-platform-configuration plugin:

  <plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
      <pomDependencies>consider</pomDependencies>
    </configuration>
  </plugin>

See the instructions on adding a dependency on a pom-first artifact. (I'm not sure whether you'll need to specify the resolver).

Regarding support for p2 repositories in Nexus, my understanding is that the p2 plugin for Nexus has since been open-sourced:

  • Nexus - P2 Repository Plugin
  • Nexus - Bundle Maker
  • Github repository for nexus-p2-repository-plugin

这篇关于如何在 tycho 中引用 mockito?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:Mockito 绕过静态方法进行测试 下一篇:具有泛型的模拟方法并在返回类型中扩展

相关文章