When automating Eclipse's “Export as Feature”, Maven/Tycho doesn't see my plugin

强颜欢笑 提交于 2019-12-19 04:08:43

问题


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>

However script throws:

[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

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


回答1:


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.

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. 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>
    
  3. 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.

  4. 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>
    

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 ../.

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.



来源:https://stackoverflow.com/questions/28739467/when-automating-eclipses-export-as-feature-maven-tycho-doesnt-see-my-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!