2016-01-29 49 views
2

我繼承了一個由Maven Tycho構建的大型Eclipse插件代碼庫。它有幾個插件模塊,兩個功能,一個目標平臺和一個更新站點。我一直在使用Java多年,但我對Eclipse插件開發和OSGi非常陌生。Maven Tycho找不到我使用maven-bundle-plugin創建的包

我發現其中一個插件模塊(我們稱之爲「核心」)有一個「lib」文件夾和少量的第三方jar。我最初認爲原作者只是懶惰,因爲我期望看到使用Maven依賴關係指定的作者。後來我發現將Maven依賴關係放入Eclipse插件是非常不平凡的事情,經過兩週多的問題解決並在各種論壇上發佈問題後,我仍然無法使其工作。我意識到,今天我沒有嘗試發佈SO,所以我們走了。

在閱讀了關於這個問題的更多信息之後,我得出結論說我需要定義一個新模塊,我們將其稱爲「maventhirdparty」,它在pom中聲明這些第三方依賴關係,然後使用「maven-bundle插件「來生成一個有效的OSGi包,然後我需要聲明新的包作爲從原始的」核心「包的依賴。

我已經完成了所有這些。不幸的是,儘管Tycho試圖解決「核心」模塊的依賴關係,但它只是說它無法找到我聲明的新包。我無法弄清楚如何生成任何附加的診斷信息,只是說它找不到它。

所以,這裏有一些輸出和文件摘錄。

這是從構建:

[INFO] Resolving dependencies of MavenProject: com.cisco.yangide:com.cisco.yangide.core:1.1.1-SNAPSHOT @ /home/opnfv/git/yangide/plugins/com.cisco.yangide.core/pom.xml 
[INFO] {osgi.os=linux, osgi.ws=gtk, org.eclipse.update.install.features=true, osgi.arch=x86} 
[ERROR] Cannot resolve project dependencies: 
[ERROR] Software being installed: com.cisco.yangide.core 1.1.1.qualifier 
[ERROR] Missing requirement: com.cisco.yangide.core 1.1.1.qualifier requires 'bundle com.cisco.yangide.maventhirdparty 1.1.1' but it could not be found 
[ERROR] 
[ERROR] See http://wiki.eclipse.org/Tycho/Dependency_Resolution_Troubleshooting for help. 
[ERROR] Cannot resolve dependencies of MavenProject: com.cisco.yangide:com.cisco.yangide.core:1.1.1-SNAPSHOT @ /home/opnfv/git/yangide/plugins/com.cisco.yangide.core/pom.xml: See log for details -> [Help 1] 

這裏的POM爲新的「maventhirdparty」模塊的摘錄:

<artifactId>com.cisco.yangide.maventhirdparty</artifactId> 
    <packaging>bundle</packaging> 
    <version>1.1.1-SNAPSHOT</version> 

    <dependencies> 
    <dependency> 
    <groupId>org.antlr</groupId> 
    <artifactId>antlr4-runtime</artifactId> 
    <version>4.0</version> 
    </dependency> 
    <dependency> 
    <groupId>org.mapdb</groupId> 
    <artifactId>mapdb</artifactId> 
    <version>1.0.4</version> 
    </dependency> 
    <dependency> 
    <groupId>org.opendaylight.yangtools</groupId> 
    <artifactId>yang-model-api</artifactId> 
    <version>0.6.1</version> 
    </dependency> 
    <dependency> 
    <groupId>org.opendaylight.yangtools</groupId> 
    <artifactId>yang-parser-impl</artifactId> 
    <version>0.6.1</version> 
    </dependency> 
    </dependencies> 

    <build> 
<plugins> 
    <plugin> 
    <groupId>org.apache.felix</groupId> 
    <artifactId>maven-bundle-plugin</artifactId> 
    <extensions>true</extensions> 
    <configuration> 
     <instructions> 
    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
    <Bundle-Version>1.1.1</Bundle-Version> 
    <Embed-Dependency> 
     antlr4-runtime, mapdb, yang-model-api, yang-parser-impl 
    </Embed-Dependency> 
    <Export-Package>org.opendaylight.yangtools.*, org.antlr.*, org.mapdb.*</Export-Package> 
    <Embed-Transitive>true</Embed-Transitive> 
    <Embed-Directory>jars</Embed-Directory> 
    <_failok>true</_failok> 
    <_nouses>true</_nouses> 
     </instructions> 
    </configuration> 
    </plugin> 
</plugins> 

這裏的生成的清單在所得束的摘錄:

Manifest-Version: 1.0 
Bnd-LastModified: 1454085545792 
Build-Jdk: 1.8.0_60 
Built-By: opnfv 
Bundle-ClassPath: .,jars/antlr4-runtime-4.0.jar,jars/mapdb-1.0.4.jar,jar 
s/yang-model-api-0.6.1.jar,jars/yang-parser-impl-0.6.1.jar 
Bundle-DocURL: https://www.opendaylight.org 
Bundle-License: https://www.eclipse.org/legal/epl-v10.html 
Bundle-ManifestVersion: 2 
Bundle-Name: com.cisco.yangide.maventhirdparty 
Bundle-SymbolicName: com.cisco.yangide.maventhirdparty 
Bundle-Vendor: OpenDaylight 
Bundle-Version: 1.1.1 
Created-By: Apache Maven Bundle Plugin 
Embed-Dependency: antlr4-runtime, mapdb, yang-model-api, yang-parser-imp 
l 
Embed-Directory: jars 
Embed-Transitive: true 
Embedded-Artifacts: ... 
Export-Package: ... 
Import-Package: ... 
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.7))" 
Tool: Bnd-3.0.0.201509101326 

這裏是來自「核心」模塊的清單:

Manifest-Version: 1.0 
Bundle-ManifestVersion: 2 
Bundle-Name: com.cisco.yangide.core 
Bundle-SymbolicName: com.cisco.yangide.core;singleton:=true 
Bundle-Version: 1.1.1.qualifier 
Bundle-Activator: com.cisco.yangide.core.YangCorePlugin 
Bundle-Vendor: Cisco Systems, Inc. 
Require-Bundle: org.eclipse.core.runtime, 
org.eclipse.jdt.core;visibility:=reexport, 
org.eclipse.text, 
org.eclipse.core.resources, 
org.eclipse.core.filesystem, 
com.cisco.yangide.maventhirdparty;bundle-version="1.1.1" 
Bundle-RequiredExecutionEnvironment: JavaSE-1.7 
Bundle-ActivationPolicy: lazy 
Export-Package: com.cisco.yangide.core, 
com.cisco.yangide.core.buffer, 
com.cisco.yangide.core.dom, 
com.cisco.yangide.core.indexing, 
com.cisco.yangide.core.parser, 
com.cisco.yangide.core.model, 
org.antlr.v4.runtime 

我能在這裏做什麼?

更新

這裏是我當前的目標平臺的定義:

<?xml version="1.0" encoding="UTF-8" standalone="no"?> 
<?pde version="3.8"?><target includeMode="feature" name="YANG IDE Target Platform" sequenceNumber="26"> 
<locations> 
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> 
<unit id="com.google.guava" version="15.0.0.v201403281430"/> 
<unit id="com.google.guava.source" version="15.0.0.v201403281430"/> 
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20140525021250/repository/"/> 
</location> 
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> 
<unit id="org.eclipse.rcp.sdk.id" version="4.5.1.M20150904-0015"/> 
<unit id="org.eclipse.graphiti.feature.feature.group" version="0.12.1.v20150916-0905"/> 
<unit id="org.sonatype.m2e.mavenarchiver.feature.feature.group" version="0.17.0.201502101659-signed-20150525172209"/> 
<unit id="org.eclipse.emf.sdk.feature.group" version="2.11.1.v20150806-0404"/> 
<unit id="org.eclipse.emf.compare.source.feature.group" version="3.1.1.201509120604"/> 
<unit id="org.eclipse.graphiti.feature.tools.feature.group" version="0.12.1.v20150916-0905"/> 
<unit id="org.eclipse.graphiti.sdk.feature.feature.group" version="0.12.1.v20150916-0905"/> 
<unit id="org.eclipse.emf.compare.feature.group" version="3.1.1.201509120604"/> 
<unit id="org.eclipse.sdk.ide" version="4.5.1.M20150904-0015"/> 
<unit id="org.eclipse.graphiti.sdk.plus.feature.feature.group" version="0.12.1.v20150916-0905"/> 
<unit id="org.eclipse.m2e.sdk.feature.feature.group" version="1.6.2.20150902-0002"/> 
<unit id="org.eclipse.emf.compare.ide.ui.feature.group" version="3.1.1.201509120604"/> 
<unit id="org.eclipse.gef.feature.group" version="3.10.1.201508170204"/> 
<unit id="org.eclipse.m2e.feature.feature.group" version="1.6.2.20150902-0002"/> 
<unit id="org.eclipse.gef.sdk.feature.group" version="3.10.1.201508170204"/> 
<unit id="org.eclipse.jdt.feature.group" version="3.11.1.v20150904-0015"/> 
<repository location="http://download.eclipse.org/releases/mars/"/> 
</location> 
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit"> 
<unit id="org.sonatype.m2e.buildhelper.feature.feature.group" version="0.15.0.201206251206"/> 
<repository location="https://repository.sonatype.org/content/repositories/forge-sites/m2e-extras/0.15.0/N/0.15.0.201206251206/"/> 
</location> 
</locations> 
</target> 

這裏是目前使用的「目標平臺的配置」插件從父POM:

<plugin> 
    <groupId>org.eclipse.tycho</groupId> 
    <artifactId>target-platform-configuration</artifactId> 
    <version>${tycho-version}</version> 
    <configuration> 
     <target> 
    <artifact> 
     <groupId>com.cisco.yangide</groupId> 
     <artifactId>com.cisco.yangide.target-platform</artifactId> 
     <version>1.1.1-SNAPSHOT</version> 
    </artifact> 
     </target> 
     <environments> 
    <environment> 
     <os>linux</os> 
     <ws>gtk</ws> 
     <arch>x86</arch> 
    </environment> 
    <environment> 
     <os>linux</os> 
     <ws>gtk</ws> 
     <arch>x86_64</arch> 
    </environment> 
    <environment> 
     <os>win32</os> 
     <ws>win32</ws> 
     <arch>x86</arch> 
    </environment> 
    <environment> 
     <os>win32</os> 
     <ws>win32</ws> 
     <arch>x86_64</arch> 
    </environment> 
    <environment> 
     <os>macosx</os> 
     <ws>cocoa</ws> 
     <arch>x86_64</arch> 
    </environment> 
     </environments> 
    </configuration> 
    </plugin> 

有什麼好奇的是,在我繼承的原始代碼庫中,上面的「target」元素被註釋掉了。我已經用這個和沒有這個來運行這個構建,而且我沒有看到有什麼不同。我猜它應該在那裏,所以我把它留下了,但原作者可能比我更瞭解這個。

關於給定的答案,我覺得這很神祕。你似乎在說,如果我有兩個插件模塊,我不能在別的地方引用這些類,而無需將引用的bundle部署到某個p2倉庫。問題是,我已經在一個或多個bundle的「Require-Bundle」屬性中引用了應用中的其他bundle,並且這些模塊構建正常,沒有錯誤。

更新

請注意,我在看其他兩種解決這個問題。

維護我正在用於此項目的nexus repo的人正在爲MavenCentral工件設置一個p2鏡像。他們遇到了一些證書問題,但我有一種感覺,這將是最終的解決方案。

另一種可能是用Graff替換Maven,使用「Wuff」插件。從我讀過的內容來看,Wuff只會將maven依賴關係並將它們透明地封裝爲OSGi包,而這隻會起作用。不幸的是,我發現Wuff的文檔有點「原始」,似乎沒有涵蓋我的應用程序結構,儘管它可能只是假設我知道所有這些應該如何工作。似乎沒有任何方法可以就此提出問題,因爲作者沒有回覆我的問題或我的電子郵件。

更新

這裏的文件只是摘錄,但你可以看到(和克隆)整個項目,減去「maventhirdparty」模塊和參考吧,在github。我最近的工作是在「forkmaster」分支,但在這方面沒有任何變化。

回答

3

我已經與Eclipse合作多年了,而且我遇到了與您描述的完全相同的問題。

事情是,tycho不'只是'解決maven reactor的依賴關係,它實際上是從目標平臺解決它們。您可能需要查看您的父pom文件才能發現它,但最有可能的情況是tycho被配置爲使用您繼承的確切目標平臺。

它看起來像

<plugin> 
    <groupId>org.eclipse.tycho</groupId> 
    <artifactId>target-platform-configuration</artifactId> 
    <version>${tycho-version}</version> 
    <configuration> 
    <target> 
     <artifact> 
     <groupId>org.example</groupId> 
     <artifactId>target-definition</artifactId> 
     <version>1.0.0-SNAPSHOT</version> 
     </artifact> 
    </target> 
    </configuration> 
</plugin> 

見文檔(https://wiki.eclipse.org/Tycho/Target_Platform)以供參考。 Tycho兼容目標平臺應使用基於uri的p2存儲庫位置。另外,也可以在你的pom.xml中指定p2 uris。無論如何,您需要將工件放入p2存儲庫。我發現最好的方法是使用p2-maven-plugin(詳細示例請參見https://github.com/reficio/p2-maven-plugin)。你需要做的是使用p2 maven插件(使用p2:站點目標)來構建你的倉庫,使它可以被http訪問(jetty或者nginx服務該目錄將工作得很好),將它添加到你的目標平臺中,然後你'重做。

這部分從P2-Maven的插件引用地址你的問題:

如果有些依賴的不是OSGi包或不在P2更新站點提供,只需在定義它們的P2-maven-插件配置,生成該網站,並使其可用碼頭(或任何其他機制)。然後將暴露站點的URL添加到目標平臺定義。以這種方式,您將在Eclipse RCP項目中擁有一致的,清單優先的依賴項管理!

希望這有幫助,並有(更多)與Eclipse開發樂趣!

+0

我已經用我的目標平臺定義和一些背景更新了帖子。我已經在應用中安裝了需要其他軟件包的軟件包,沒有任何問題。爲什麼這個新套件有什麼不同? –

+0

>你似乎在說,如果我有兩個插件模塊,我不能在別的地方引用這些類,而無需將引用的包部署到某個p2倉庫。 – execc

+0

>問題是,我已經在一個或多個bundle的「Require-Bundle」屬性中引用了應用中的其他bundle,並且這些模塊構建正常,沒有錯誤。 –