2016-01-29 50 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,并且这些模块构建正常,没有错误。 –