2011-06-07 55 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