在常规 Maven 构建中使用来自 Eclipse p2 存储库的依赖项? [英] Use dependencies from Eclipse p2 repository in a regular Maven build?

查看:33
本文介绍了在常规 Maven 构建中使用来自 Eclipse p2 存储库的依赖项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在常规"Maven 3 构建(例如 JAR 或 WAR 打包)中使用来自远程 Eclipse p2 存储库的依赖项 - 所有这些都不需要将 p2 存储库转换为本地 Maven 存储库(这就是 osgi-to-maven2 和 m4e 似乎可以).

I'd like to use dependencies from a remote Eclipse p2 repository in a "regular" Maven 3 build (e.g. JAR or WAR packaging) - all without converting the p2 repo to a local Maven repo (which is what osgi-to-maven2 and m4e seem to do).

理想情况下,我只使用 http://maven.eclipse.org/nexus/,但这不会t(还?)包含许多包.

Ideally, I'd just use http://maven.eclipse.org/nexus/, but that doesn't (yet?) contain many bundles.

使用 Maven 的 systemPath 不算!

Using Maven's systemPath doesn't count!

推荐答案

看来我正在回答我自己的另一个问题..

Looks like I'm answering another of my own questions..

首先,您可以使用 Tycho 添加对来自 P2 存储库的包的依赖:

First of all, you can use Tycho to add a dependency on a bundle from a P2 repository:

  • 配置构建以使用 tycho-maven-plugin.
  • 指定 P2 存储库.
  • 将打包设置为eclipse-plugin".
  • 为您的构建创建一个清单并使用 Require-Bundle 来声明依赖项(例如 org.eclipse.xsd).还将 Bundle-Version 设置为我们在 pom.xml 中用于构建的相同版本.

让我们试一试:

$ mvn dependency:tree
[INFO] com.example:org.eclipse.xsd:eclipse-plugin:0.0.1
[INFO] +- p2.eclipse-plugin:org.eclipse.xsd:jar:2.6.0.v20100914-1218:system
[INFO] ...
[INFO] - p2.eclipse-plugin:org.eclipse.core.filesystem:jar:1.3.1.R36x_v20100727-0745:system

我们的依赖项已成功从 P2 存储库解决.不幸的是,我们还没有完成.该依赖项已添加到系统范围内,这意味着如果我们创建一个依赖于我们的构建的 web 应用程序,则不会包含这些工件.为了解决这个问题,我们首先将依赖项中包含的所有类解压缩到某个目录,然后将该目录重新打包为 jar 并将其用作我们构建的最终工件.

Our dependency has sucessfully been resolved from the P2 repository. Unfortunately, we're not done yet. The dependency has been added with system scope, which means that the artifacts won't be included if we create a webapp that depends on our build. To work around that, we'll first unpack all classes contained in the dependency to some directory, and then re-package that directory as a jar and use it as the final artifact of our build.

对于第一部分(解包),我们将 maven-dependency-plugin 添加到我们的构建中,并将其配置为在打包阶段运行其解包依赖项目标.对于第二部分(重新打包),我们将 maven-assembly-plugin 添加到我们的构建中,并将其配置为在打包阶段运行其单一目标.我们还需要创建和配置自定义程序集描述符.

For the first part (unpacking), we add the maven-dependency-plugin to our build and configure it to run its unpack-dependencies goal during the package phase. For the second part (re-packaging), we add the maven-assembly-plugin to our build and configure it to run its single goal during the package phase. We also need to create and configure a custom assembly descriptor.

我们的构建现在由 3 个文件组成: pom.xml 中的构建文件:

Our build now consists of 3 files: The build file in pom.xml:

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>org.eclipse.xsd</artifactId>
    <version>0.0.1</version>
    <packaging>eclipse-plugin</packaging>
    <repositories>
        <repository>
            <id>helios</id>
            <layout>p2</layout>
            <url>http://download.eclipse.org/releases/helios</url>
        </repository>
    </repositories>
    <build>
        <plugins>
            <plugin>
                <groupId>org.eclipse.tycho</groupId>
                <artifactId>tycho-maven-plugin</artifactId>
                <version>0.12.0</version>
                <extensions>true</extensions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>unpack-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/dependency</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/repackaged.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

META-INF/MANIFEST.MF 中的清单:

The manifest in META-INF/MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Ignored
Bundle-SymbolicName: Ignored
Bundle-Version: 0.0.1
Require-Bundle: org.eclipse.xsd
Bundle-Vendor: Ignored

src/main/assembly/repackaged.xml 中的程序集描述符:

The assembly descriptor in src/main/assembly/repackaged.xml:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>repackaged</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
      <fileSet>
        <directory>${project.build.directory}/dependency/</directory>
        <outputDirectory>/</outputDirectory>
        <useDefaultExcludes>true</useDefaultExcludes>
      </fileSet>
    </fileSets>
</assembly>

现在 mvn package 将创建一个 jar 文件,其中包含来自我们 P2 依赖项的所有代码,重新打包为适当的 Maven 工件,准备用作另一个项目中的依赖项.

Now mvn package will create a jar file that contains all the code from our P2 dependency, re-packaged as a proper Maven artifact, ready to be used as a dependency in another project.

$ jar tf target/org.eclipse.xsd-0.0.1-repackaged.jar 
org/eclipse/xsd/ecore/XSDEcoreBuilder$1.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$2.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$Comparator.class
org/eclipse/xsd/ecore/XSDEcoreBuilder$EffectiveOccurrence.class
org/eclipse/xsd/ecore/XSDEcoreBuilder.class

这篇关于在常规 Maven 构建中使用来自 Eclipse p2 存储库的依赖项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆