【问题标题】:Build local eclipse plugins using tycho pointing to local p2 repository使用指向本地 p2 存储库的 tycho 构建本地 eclipse 插件
【发布时间】:2013-08-01 17:01:07
【问题描述】:

我正在创建一些需要第三方插件和功能的 Eclipse 插件和功能。为了将这些依赖项包含到我的项目中,我创建了一个 p2 布局存储库。

注意:我的 p2 工件不是 Maven 项目...但是,我使用的是 Maven 风格的构建。这是 p2 存储库的 pom.xml

<properties>
    <tycho-version>0.18.0</tycho-version>
  </properties>

  <repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
  </repositories>

  <build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho.extras</groupId>
            <artifactId>tycho-p2-extras-plugin</artifactId>
            <version>${tycho-version}</version>
            <executions>
                <execution>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>publish-features-and-bundles</goal>
                    </goals>
                    <configuration>
                        <compress>false</compress>
                        <artifactRepositoryLocation>/mypath/target/repository</artifactRepositoryLocation>
                        <metadataRepositoryLocation>/mypath/target/repository</metadataRepositoryLocation>
                        <sourceLocation>/mypath/src</sourceLocation>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-p2-repository-plugin</artifactId>
            <version>${tycho-version}</version>
            <configuration>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>verify-repository</goal>
                        <goal>archive-repository</goal>
                    </goals>
                    <configuration>
                        <compress>false</compress>
                        <includeAllDependencies>true</includeAllDependencies>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>  
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-p2-publisher-plugin</artifactId>
          <version>${tycho-version}</version>
          <configuration>
            <publishArtifacts>true</publishArtifacts>
          </configuration>
        </plugin>
        <plugin><!-- enable the Tycho build extension -->
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho-version}</version>
            <extensions>true</extensions>
        </plugin>   
    </plugins>
  </build>

以上构建成功,并创建(并验证)一个 p2 存储库。我在项目的target/ 目录中得到以下结构

- Project
    ..
    ..
    - target
      - p2agent
         - org.eclipse.equinox.p2.core
         - org.eclipse.equinox.p2.engine
      - repository
        - features
        - plugins
          artifacts.xml 
          content.xml
      <projectname>-<version>.zip <!-- This contains same things as repository directory here -->

现在,我使用 Tycho 构建我的插件和功能,并参考我在上面创建的 p2 存储库。我的插件和功能有以下项目结构

- bundle.parent
  - bundle.mainplugin
  - bundle.mainplugin.test.fragment 
  - bundle.mainplugin.feature

这是我的 bundle.parent pom.xml

<repositories>
        <repository>
                <id>eclipse-platform-m6</id>
                <layout>p2</layout>
                <url>http://download.eclipse.org/eclipse/updates/3.8</url>
        </repository>
        <repository>
                <id>third-party-eclipse-plugins</id>
                <layout>p2</layout>
                <url>file:///.../target/repository</url>
         </repository>
  </repositories>
  <modules>
    <module>../bundle.mainplugin</module>
    <module>../bundle.mainplugin.test.fragment</module>
    <module>../bundle.mainplugin.feature</module>
  </modules>
  <build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>tycho-maven-plugin</artifactId>
      <version>${tycho-version}</version>
      <extensions>true</extensions>
    </plugin>
  </plugins>
</build>

最后,我在父 pom.xml 上运行目标 mvn clean install。不幸的是,当我的插件中的类扩展插件中的某些类时,mvn-compile 会引发编译问题。 (这些类在运行时也是必需的)。这是错误:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:0.18.0:compile (default-compile
) on project <Project Name>: Compilation failure
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: copied.org.apache.maven.plugin.CompilationFailureException: Compilation failure
    at copied.org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:442)
    at org.eclipse.tycho.compiler.AbstractOsgiCompilerMojo.execute(AbstractOsgiCompilerMojo.java:239)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
    ... 19 more

我的问题:

从编译器错误来看,我相信 Tycho 不会以某种方式将这些第三方工件提供给我存在编译器错误的类。有没有办法确定我的插件类是否存在于 Tycho 类路径中?

更新

通过this location检查了我希望在 Tycho reactor 中提供的第三方捆绑包的可用性

java -jar /home/.../eclipse-3.8.2/plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -debug -consolelog -application org.eclipse.equinox.p2.director -repository file:///home/../target/repository -list

所有第三方捆绑包均已成功显示。

【问题讨论】:

  • file:///.../target/repository URL 不起作用。解决方案可能是 Laurents 回答或 this other question。我不知道你是如何进入编译步骤的。我假设依赖解析已经失败。
  • 我已退出该项目,无法再访问代码来测试解决方案

标签: eclipse-plugin tycho


【解决方案1】:

Sebastian Zarnekow 的回答给了我一个提示。

Error while building an xtext project with ant: Generation of the Grammar classes fails

您可以从错误消息中推断出,maven 无法通过注入创建语言模型。原因在上面的链接中有解释:

Xtext 使用 EMF 的 platform:/resource URI 方案。

解决方案是你需要给 EMFGenerator 一个新的模型目录应该在哪里的声明。在**.mwe2文件中,替换如下代码

fragment = ecore.EMFGeneratorFragment auto-inject {}

fragment = ecore.EMFGeneratorFragment auto-inject {
    javaModelDirectory = "/${projectName}/src-gen"
}

应该可以解决问题。

【讨论】:

  • 这救了我一晚!! Tycho/Maven/Xtext 的构建非常令人困惑,感谢您的技巧。
【解决方案2】:

对于同样遇到此问题的任何人,您也可以尝试使用:

${project.basedir}

所以,假设您有以下目录:

- projects:
    - main-project
    - local-repository

在父 pom(即:main-project/pom.xml)中,使用相对路径引用本地存储库,方式如下:

<url>file:${project.basedir}/target/repository</url>

【讨论】:

  • file:${project.basedir} 在 Windows 系统上产生无效的 URL。请改用 ${project.baseUri}。
  • 或者在 Linux 中尝试&lt;url&gt;file:${user.home}/somewhere/target/repository&lt;/url&gt;,以防您的 p2 存储库不在项目的子目录中。
【解决方案3】:

只需替换:

<url>file:///.../target/repository</url>

作者:

<url>file:<projectname>/deploy/target/repository</url>

(如果你的父 pom.xml 是你的根文件夹)

【讨论】:

  • 感谢您的评论。我已退出我正在工作的项目,无法尝试您的建议。
猜你喜欢
  • 2016-09-29
  • 2020-03-02
  • 2018-10-25
  • 2011-03-06
  • 2016-05-22
  • 2013-10-18
  • 1970-01-01
  • 2021-08-09
  • 2019-12-13
相关资源
最近更新 更多