gpt4 book ai didi

java - Maven Tycho 找不到我用 maven-bundle-plugin 创建的包

转载 作者:行者123 更新时间:2023-11-30 08:05:23 25 4
gpt4 key购买 nike

我继承了一个使用 Maven Tycho 构建的大型 Eclipse 插件代码库。它有几个插件模块、两个功能、一个目标平台和一个更新站点。我使用 Java 已经很多年了,但是我对 Eclipse 插件开发和 OSGi 还是很陌生。

我发现其中一个插件模块(我们将其称为“核心”)有一个“lib”文件夹,其中包含一些第三方 jar。我最初认为原始作者只是懒惰,因为我希望看到那些使用 Maven 依赖项指定的人。后来我发现将 Maven 依赖项放入 Eclipse 插件非常重要,经过两个多星期的努力解决这个问题并在各种论坛上发布问题后,我仍然无法让它工作。我今天意识到我没有尝试过 SO 发布,所以我们开始吧。

在阅读了更多关于该问题的内容后,我得出结论,我需要定义一个新模块,我们称之为“maventhirdparty”,它在pom中声明那些第三方依赖项,然后使用“maven-bundle-plugin”来生成一个有效的 OSGi 包,然后我需要将新包声明为原始“核心”包的依赖项。

我已经完成了这一切。不幸的是,尽管生成的包和 list 对我来说看起来是正确的,但当 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]

以下是新的“maventhirdparty”模块的 POM 摘录:
  <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>

以下是生成的包中生成的 list 的摘录:
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

这是“核心”模块的 list :
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 中“target-platform-configuration”插件的当前使用:
  <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>

奇怪的是,在我继承的原始代码库中,上面的“目标”元素被注释掉了。我已经在有和没有这个的情况下运行了构建,我看不出有什么区别。我猜它应该在那里,所以我把它留在了,但原作者可能比我更了解这一点。

关于给定的答案,我觉得这很神秘。您似乎在说,如果我有两个插件模块,如果不将引用的包部署到某处的 p2 存储库,我就无法从一个到另一个引用这些类。问题是,我已经在一个或多个捆绑包的“Require-Bundle”属性中引用了应用程序中的其他捆绑包,并且这些模块构建良好,没有错误。

更新 :

请注意,我正在寻找解决此问题的其他两种解决方法。

维护我用于此项目的 nexus 存储库的人员正在为 MavenCentral Artifact 设置 p2 镜像。他们对此有一些证书问题,但我觉得这将是最终的解决方案。

另一种可能性是使用“Wuff”插件将 Maven 替换为 Gradle。从我所读到的,Wuff 将只获取 maven 依赖项并将它们透明地打包为 OSGi 包,这将起作用。不幸的是,我发现 Wuff 的文档有点“原始”,似乎没有涵盖我的应用程序结构,尽管它可能只是假设我知道所有这些应该如何工作。似乎没有任何方法可以就此提出问题,因为作者没有回复我的问题或我的电子邮件。

更新 :

此处的文件只是摘录,但您可以在 github 上查看(并克隆)整个项目,减去“maventhirdparty”模块及其引用。 .我最近的工作是在“forkmaster”分支上,但在这方面没有变化。

最佳答案

我与 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。在任何情况下,您都需要将 Artifact 放入 p2 存储库。我发现最好的方法是使用 p2-maven-plugin (有关详细示例,请参见类似: https://github.com/reficio/p2-maven-plugin)。您需要做的是使用 p2 maven 插件(具有 p2:site 目标)构建您的存储库,使其 http 可访问(为目录提供服务的 jetty 或 nginx 可以正常工作),将其添加到您的目标平台中,然后您'重做。

这部分来自 p2-maven-plugin 引用解决了您的问题:

If some of your dependencies are not OSGi bundles or are not available in P2 update sites, SIMPLY define them in the p2-maven-plugin config, generate the site and make it available using jetty (or any other mechanism). Then add the URL of the exposed site to the target platform definition. In such a way you will have a consistent, manifest-first dependency management in Eclipse RCP project!



希望这会有所帮助,并在 Eclipse 开发中获得(更多)乐趣!

关于java - Maven Tycho 找不到我用 maven-bundle-plugin 创建的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35091186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com