Maven/Tycho采用了错误的捆绑版本

xon*_*ned 3 build eclipse-rcp tycho maven

我正在尝试使用tycho构建我的eclipse-plugin.

我的包com.mycompany.math需要org.apache.commons.math-1.2.0,它安装在我的p2-repository中.依赖项在org.mycompany.math的MANIFEST.MF中定义:

Require-Bundle: org.apache.commons.math;bundle-version="1.2.0",
Run Code Online (Sandbox Code Playgroud)

在我的构建过程中,我收到org.apache.commons.math-classes无法解决的错误消息.在构建开始之前,maven/tycho下载了2.1.0版本.所以,我的问题是,为什么maven/tycho下载2.1.0,当我在MANIFEST.MF中定义我使用1.2.0时.

您可以在我的父pom.xml中看到我定义了三个p2-repository.最后一个,包含我所需的1.2.0版本.

我的父pom.xml:

<project...>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>com.mycompany.build</artifactId>
<version>3.1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Build</name>
<description>Parent POM for full builds</description>

<modules>
    <!-- my modules -->
</modules>

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

<repositories>
    <!-- configure p2 repository to resolve against -->
    <repository>
        <id>juno</id>
        <layout>p2</layout>
        <url>http://download.eclipse.org/releases/juno/</url>
    </repository>
    <repository>
        <id>orbit</id>
        <layout>p2</layout>
<url>http://download.eclipse.org/tools/orbit/downloads/drops/S20121021123453/repository/</url>
    </repository>
    <repository> <-- CONTAINS ORG.APACHE.COMMONS.MATH-1.2.0 !
        <id>comp</id>
        <layout>p2</layout>
        <url>http:our-adress.com/p2/</url>
    </repository>
</repositories>

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

        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho-version}</version>
            <configuration>
                <pomDependencies>consider</pomDependencies>
                <environments>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
    </plugins>
</build>


<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>1.2</version>
        </dependency>
    </dependencies>
</dependencyManagement>
Run Code Online (Sandbox Code Playgroud)

还有我的com.company.math pom.xml

<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>com.mycompany.math</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>Math</name>
<packaging>eclipse-plugin</packaging>

<parent>
    <groupId>com.mycompany</groupId>
    <artifactId>com.mycompany.build</artifactId>
    <version>3.1.0-SNAPSHOT</version>
    <relativePath>../com.mycompany.build</relativePath>
</parent>


<dependencies>
    <dependency>
        <groupId>commons-math</groupId>
        <artifactId>commons-math</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

obe*_*ies 9

问题是你的Require-Bundle语句过于笼统:Require-Bundle: org.apache.commons.math;bundle-version="1.2.0"实际上你指定在版本1.2.0 或更高版本中需要数学包.

您应该指定只需要1.2.0或兼容版本.这可以通过以下方式完成Require-Bundle: org.apache.commons.math;bundle-version="[1.2.0,2.0.0)".这个语句可以防止你的bundle在运行时连接到(明显不兼容的)2.1版本的math包(这也很重要!),它也可能会修复你的构建问题.

如果目标平台中存在这样的版本(例如,在您的情况下,任何已配置的p2存储库或POM依赖关系中),Tycho可能仍会针对构建的数学包的更高1.x版本进行解析.如果是这种情况,但您希望强制在构建中使用1.2版本,则需要控制目标平台的内容.(Maven <dependencyManagement>是不够的,因为它对您配置的p2存储库没有影响.)您可以通过在Tycho的目标平台配置中指定过滤器来执行此操作:

<plugin>
   <groupId>org.eclipse.tycho</groupId>
   <artifactId>target-platform-configuration</artifactId>
   <version>${tycho-version}</version>
   <configuration>
      <filters>
         <filter>
            <type>eclipse-plugin</type>
            <id>org.apache.commons.math</id>
            <restrictTo>
               <version>1.2.0</version>
            </restrictTo>
         </filter>
      </filters>
   </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)