自动化 Eclipse 的“导出为功能"时,Maven/Tycho 看不到我的插件

2022-01-16 00:00:00 eclipse-plugin eclipse maven tycho

我的工作区中有一个插件和一个功能项目.当我通过 File > Export As > Feature 手动导出功能时,一切正常.我正在尝试编写一个自动插件构建和导出脚本来摆脱这个苦差事.我将功能项目转换为 Maven 项目并在 pom.xml 中填充:

I have a plugin and a feature project in my workspace. When I export the feature manually via File > Export As > Feature everything works well. I'm trying to write an automatic plugin building and exporting script to get rid of this chore. I converted feature project to Maven project and filled pom.xml with:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>MyProject</groupId>
   <artifactId>NMGDBPluginFeature</artifactId>
   <version>1.0.0-SNAPSHOT</version>
   <packaging>eclipse-feature</packaging>

   <properties>
      <tycho-version>0.22.0</tycho-version>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
   </properties>

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

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

</project>

然而脚本抛出:

[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: NMGDBPluginFeature.feature.group 1.0.0.qualifier
[ERROR]   Missing requirement: NMGDBPluginFeature.feature.group 1.0.0.qualifier requires 'GDBFifoBlocks [1.0.0.gdbfifoblocks]' but it could not be found

怎么会这样?我认为 pom.xml 使用项目的 feature.xml ,不是吗?什么是合适的配置?

How could that happen? I thought pom.xml uses feature.xml of project, doesn't it? What is a proper configuration?

推荐答案

到目前为止,您的配置看起来不错.但是,您目前只有针对您的功能的自动构建,而不是针对插件的自动构建.与 Eclipse 导出向导不同,eclipse-feature 仅处理 feature.xml - 它期望引用的插件在其他地方构建.

So far, your configuration looks good. However you currently only have an automated build for your feature, but not the for the plugin. Unlike the Eclipse export wizard, eclipse-feature only processes the feature.xml - and it expects that the referenced plugins are built elsewhere.

所以你需要做的是建立一个Maven反应器,其中包括一个eclipse-feature和一个eclipse-plugin项目.以下是您的操作方法:

So what you need to do is to set up a Maven reactor which includes both an eclipse-feature and an eclipse-plugin project. Here is how you do this:

  1. 将当前的 pom.xml 设为父 POM:将包装更改为 pom,将 artifactId 调整为有意义的内容(例如 MyProject.parent),然后将 pom.xml 移动到工作区中的新通用项目中.
  2. 在功能项目的根目录下添加一个 pom.xml:

  1. Make your current pom.xml the parent POM: Change the packaging to pom, adapt the artifactId to something which makes sense (e.g. MyProject.parent), and move the pom.xml into a new general project in your workspace.
  2. Add a pom.xml in the root of the feature project:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>MyProject</groupId>
    <artifactId>MyProject.parent</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>relative/path/to/parent/project</relativePath>
  </parent>

  <artifactId>NMGDBPluginFeature</artifactId>
  <packaging>eclipse-feature</packaging>

</project>

  • 在插件项目的根目录中添加另一个 pom.xml,除了 artifactId 之外与上面的相同 - 这需要与插件的 Bundle-SymbolicName - 以及需要为 eclipse-pluginpackaging.

  • Add another pom.xml in the root of the plugin project, which is the same as the one above except for the artifactId - this needs to be the same as the plugin's Bundle-SymbolicName - and the packaging which needs to be eclipse-plugin.

    通过在父 POM 中添加 <modules> 部分以及这些项目的路径,将插件和功能项目包含在 Maven 反应器中:

    Include the plugin and feature projects in the Maven reactor by adding a <modules> section in the parent POM with the paths to these projects:

      <modules>
        <module>relative/path/to/plugin/project</module>
        <module>relative/path/to/feature/project</module>
      </modules>
    

  • 请注意,需要调整路径,以便它们适合磁盘上的项目位置(可能与 Eclipse 工作区中显示的不同).路径需要是相对的,所以它们可能以 ../.

    Note that the paths need to be adapted so that they are correct for the project locations on disk (which may be different to what is shown in the Eclipse workspace). The paths need to be relative, so they probably start with ../.

    现在您可以在父 POM 上触发 Maven 构建,并且该功能应该能够解析对您的插件的引用.在 Eclipse 中,您可以从 pom.xml 文件的上下文菜单中触发 Maven 构建.或者,如果您还将父项目转换为 Maven 项目,您还可以从项目根目录的上下文菜单中运行 Maven 构建.

    Now you can trigger a Maven build on your parent POM, and the feature should be able to resolve the reference to your plugin. In Eclipse, you can trigger the Maven build from the context menu of the pom.xml file. Or, if you also convert the parent project to a Maven project, the you can also run Maven builds from the context menu of the project root.

    相关文章