2011-06-07 57 views
5

可能重复:
How to reference mockito within tycho?无法解析的Mockito依赖于第谷项目

我要去跟第谷的测试功能项目建设,但它未能解决中列出的依赖我的pom来自Maven中央存储库,它在我的父pom中列出。下面是相关的部分从我父POM:

<properties> 
      <tycho-version>0.12.0</tycho-version> 
    </properties> 

    <repositories> 
      <repository> 
        <id>helios</id> 
        <layout>p2</layout> 
        <url>http://download.eclipse.org/releases/helios/</url> 
      </repository> 
    </repositories> 

    <pluginRepositories> 
      <pluginRepository> 
        <id>central</id> 
        <name>Maven Plugin Repository</name> 
        <url>http://repo1.maven.org/maven2</url> 
        <layout>default</layout> 
        <snapshots> 
          <enabled>false</enabled> 
        </snapshots> 
        <releases> 
          <updatePolicy>never</updatePolicy> 
        </releases> 
      </pluginRepository> 
    </pluginRepositories> 

    <build> 
      <plugins> 
        <plugin> 
          <groupId>org.eclipse.tycho</groupId> 
          <artifactId>tycho-maven-plugin</artifactId> 
          <version>${tycho-version}</version> 
          <extensions>true</extensions> 
        </plugin> 
        <plugin> 
          <groupId>org.eclipse.tycho</groupId> 
          <artifactId>target-platform-configuration</artifactId> 
          <version>${tycho-version}</version> 

          <configuration> 
            <pomDependencies>consider</pomDependencies> 

            <resolver>p2</resolver> 

            <environments> 
              <environment> 
                <os>linux</os> 
                <ws>gtk</ws> 
                <arch>x86_64</arch> 
              </environment> 
              <environment> 
                <os>win32</os> 
                <ws>win32</ws> 
                <arch>x86</arch> 
              </environment> 
            </environments> 
          </configuration> 
        </plugin> 
      </plugins> 
    </build> 

,并在这里我有POM:

<modelVersion>4.0.0</modelVersion> 
    <parent> 
      <artifactId>parent</artifactId> 
      <groupId>com.example</groupId> 
      <version>1.0.0-SNAPSHOT</version> 
    </parent> 
    <groupId>com.example</groupId> 
    <artifactId>com.example.testing.feature</artifactId> 
    <version>1.0.0-SNAPSHOT</version> 
    <packaging>eclipse-feature</packaging> 

    <dependencyManagement> 
      <dependencies> 
        <dependency> 
          <groupId>org.mockito</groupId> 
          <artifactId>mockito-all</artifactId> 
          <version>1.8.5</version> 
        </dependency> 
      </dependencies> 
    </dependencyManagement> 

    <dependencies> 
      <dependency> 
        <groupId>org.mockito</groupId> 
        <artifactId>mockito-all</artifactId> 
      </dependency> 
    </dependencies> 

,当我在我的功能项目运行mvn清洁套装,我得到如下:

[INFO]添加存储库http://download.eclipse.org/releases/helios/ [INFO]添加存储库http://download.eclipse.org/releases/helios/ [调试]添加了p2存储库helios(http://download.eclipse.org/releases/helios/ ) [DEBUG]忽略Maven仓库中央(http://repo1.maven.org/maven2

然后我的构建失败,因为我的依赖无法解析。我错过了什么吗?这是因为为目标平台配置配置了p2解析器吗?

+0

控制台输出最重要的部分丢失了:哪个依赖项无法解析?可能是'org.mockito.mockito-all'的传递依赖链中的某些东西(参见[这个答案](http://stackoverflow.com/a/11951980/1523648)) – oberlies 2012-08-27 15:56:44

回答

7

确实看起来你是对的。

首先,创建一个目标定义文件(.TARGET),并把它放在一个Maven项目中,看到这里例如目标:https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/platform/indigo.target

您需要的.TARGET文件附加到神器,使用建立帮助:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.3</version> 
    <executions> 
     <execution> 
      <id>attach-artifacts</id> 
      <phase>package</phase> 
      <goals> 
       <goal>attach-artifact</goal> 
      </goals> 
      <configuration> 
       <artifacts> 
        <artifact> 
         <file>indigo.target</file> 
         <type>target</type> 
         <classifier>indigo</classifier> 
        </artifact> 
       </artifacts> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

(从https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/platform/pom.xml

然后,在父POM或使用该目标定义文件的插件项目,你需要配置目标平台的配置的Maven的“目标” plugi n,例如:

<plugin> 
    <groupId>org.eclipse.tycho</groupId> 
    <artifactId>target-platform-configuration</artifactId> 
    <version>${tycho-version}</version> 
    <configuration> 
     <resolver>p2</resolver> 
     <ignoreTychoRepositories>true</ignoreTychoRepositories> 
     <target> 
      <artifact> 
       <groupId>com.eclipsesource.sandbox.weaving.demo</groupId> 
       <artifactId>com.eclipsesource.sandbox.weaving.demo.platform</artifactId> 
       <version>0.1.0-SNAPSHOT</version> 
       <classifier>indigo</classifier> 
      </artifact> 
     </target> 
     <environments> 
      <environment> 
       <os>${build.os}</os> 
       <ws>${build.ws}</ws> 
       <arch>${build.arch}</arch> 
      </environment> 
     </environments> 
    </configuration> 
</plugin> 

(从https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/releng/pom.xml拍摄)

然后您的项目(S)应该建立非常漂亮,使用第谷。 :-)如果您的.target引用远程p2存储库并且不在p2捆绑包池中,则必需的工件将自动下载。

祝你好运!

已知问题:

[WARNING] Target location type: Profile is not supported 

由于第谷0.12.0的,这意味着第谷的 “Eclipse安装” 目标源型cannot be used(?还),与 “目录”,沿着 “功能” 。

解决方案:使用“更新站点”目标源。

如果您还没有的更新站点,这里是产生从一个Eclipse更新站点(或从含束的任何文件夹,对于这个问题):

/opt/eclipse_rcp/eclipse -consolelog -nosplash -verbose \ 
    -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \ 
    -metadataRepository file:/home/ceefour/p2/bonita/ \ 
    -artifactRepository file:/home/ceefour/p2/bonita/ \ 
    -source /home/ceefour/BOS-5.5.1/studio/ \ 
    -publishArtifacts 

注:

  • 变化的/ opt/eclipse_rcp到您自己的Eclipse SDK安装
  • metadataRepository和artifactRepository是在新的更新站点将要创建的文件夹
  • 源是 - 你猜对了 - 包含原始包的文件夹/安装
+0

这让我走上了正确的道路。我在Hendy的答案中使用了一些建议来解决我的问题。感谢您的回复。 – 2011-09-23 04:26:19

+1

我得到了同样的问题,但我无法解决它使用您的答案。我遵循你的指示,创建了目标平台,创建了一个包含mockito的定制p2仓库,但eclipse仍然无法解析mockito。我试图在pom.xml中指定不依赖的依赖项(在xml文件中没有错误标记,但在eclipse中)。当我尝试在清单中将mockito添加为必需的包时,它不会显示在列表中。你有没有猜到我可能做错了什么?提前致谢。 – 2011-09-24 16:40:22

+0

这个解决方案太复杂了。如果您还没有目标文件,直接添加包含POM缺失需求的p2存储库([layout = p2](http://wiki.eclipse.org/Tycho/Target_Platform# Layout_p2))。 – oberlies 2012-08-27 16:26:39