在常规Maven构建中使用Eclipse p2仓库的依赖关系? [英] Use dependencies from Eclipse p2 repository in a regular Maven build?

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

问题描述

我想在一个常规Maven 3构建(例如JAR或WAR打包)中使用远程Eclipse p2存储库中的依赖关系 - 所有这些都不会将p2 repo转换为本地的Maven repo(这是osgi-to -maven2和m4e似乎做了)。



理想情况下,我只是使用 http://maven.eclipse.org/nexus/ ,但是这不包含许多捆绑包。



使用Maven的systemPath不会t计数!

解决方案

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



首先,您可以使用Tycho从P2存储库中添加一个依赖关系:




  • 配置构建使用tycho-maven-plugin。

  • 指定P2存储库。

  • 将包装设置为eclipse-plugin。

  • 为构建创建一个清单,并使用Require-Bundle来说明依赖关系(例如org.eclipse.xsd)。还将Bundle-Version设置为我们在pom.xml中构建的相同版本。



让我们试一下: p>

  $ mvn依赖: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存储库中成功解决。不幸的是,我们还没有完成依赖关系已经添加了系统范围,这意味着如果我们创建一个依赖于我们的构建的webapp,那么这些工件将不被包含。要解决这个问题,我们首先将包含在依赖关系中的所有类解压缩到一些目录中,然后将该目录重新打包成jar,并将其用作我们构建的最终工件。



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



我们的构建现在由3个文件组成: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>
<执行>
< execution>
< id> unpack-dependencies< / id>
< phase> package< / phase>
< goals>
< goal> unpack-dependencies< / goal>
< / goals>
< configuration>
< outputDirectory> $ {project.build.directory} /依赖关系< / 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>
<执行>
< execution>
< id> make-assembly< / id>
< phase> package< / phase>
< goals>
< goal> single< / goal>
< / goals>
< / execution>
< / executions>
< / plugin>
< / plugins>
< / build>
< / project>

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

  Manifest-Version:1.0 
Bundle-ManifestVersion:2
Bundle-Name:忽略
Bundle-SymbolicName:忽略
捆绑版本:0.0.1
需求捆绑:org.eclipse.xsd
捆绑供应商:忽略

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

 < assembly xmlns $
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>重新打包< / 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包将创建一个包含来自我们的P2依赖关系的所有代码的jar文件,重新打包作为一个适当的Maven工件,准备在另一个项目中用作依赖。

  $ 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


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

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

Using Maven's systemPath doesn't count!

解决方案

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

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

  • Configure the build to use tycho-maven-plugin.
  • Specify a P2 repository.
  • Set packaging to "eclipse-plugin".
  • Create a manifest for your build and use Require-Bundle to state the dependency (e.g. org.eclipse.xsd). Also set Bundle-Version to the same version we used for our build in pom.xml.

Let's give that a try:

$ 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

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.

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.

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>

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

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>

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天全站免登陆