10

我有一个使用 Tycho 插件使用 Maven 构建的 Eclipse RCP 应用程序。有一个主 POM,其中包含作为模块的所有插件和功能。

如果我使用 Maven安装主 POM,则生成的反应器构建工作正常。所有模块都已构建并且安装成功

但是,如果我单独构建其中一个 Eclipse插件,则无法解析它对应用程序其他插件的依赖关系

对第三方库(例如 Eclipse 平台)的依赖似乎运行良好。我们的应用程序的 Eclipse 插件只有这种类型的依赖才能成功构建。

控制台输出如下:

[INFO] Resolving dependencies of MavenProject: com.mycompany.myproduct:com.mycompany.myproduct.gui.editors:1.8.15-SNAPSHOT @ /<path>/com.mycompany.myproduct.gui.editors/pom.xml
[INFO] Cannot complete the request.  Generating details.
[INFO] Cannot complete the request.  Generating details.
[INFO] {osgi.ws=gtk, osgi.os=linux, osgi.arch=x86, org.eclipse.update.install.features=true}
[ERROR] Cannot resolve project dependencies:
[ERROR]   Software being installed: com.mycompany.myproduct.gui.editors 1.8.15.qualifier
[ERROR]   Missing requirement: com.mycompany.myproduct.gui.editors 1.8.15.qualifier requires 'bundle com.mycompany.myproduct.preferences 1.8.15' but it could not be found
[ERROR] 
[ERROR] Internal error: java.lang.RuntimeException: "No solution found because the problem is unsatisfiable.": ["Unable to satisfy dependency from com.mycompany.myproduct.gui.editors 1.8.15.qualifier to bundle com.mycompany.myproduct.preferences 1.8.15.", "Unable to satisfy dependency from com.mycompany.myproduct.gui.editors 1.8.15.qualifier to bundle com.mycompany.myproduct.gui.utils 1.8.15.", "No solution found because the problem is unsatisfiable."] -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: "No solution found because the problem is unsatisfiable.": ["Unable to satisfy dependency from com.mycompany.myproduct.gui.editors 1.8.15.qualifier to bundle com.mycompany.myproduct.preferences 1.8.15.", "Unable to satisfy dependency from com.mycompany.myproduct.gui.editors 1.8.15.qualifier to bundle com.mycompany.myproduct.gui.utils 1.8.15.", "No solution found because the problem is unsatisfiable."]
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:168)
        ...

由于反应堆构建成功,所有插件构建都在我们公司的存储库中(我们使用 Artifactory)。在 Artifactory 网络应用程序中,我清楚地看到了该preferences插件的 1.8.15-SNAPSHOT 版本。但是,似乎无法访问此存储库。

存储库信息在settings.xml文件中指定。请注意,父 POM 已从该存储库中成功检索:

[INFO] Scanning for projects...
Downloading: http://artifactory.buildnet.mycompany.com/artifactory/libs-snapshot-local/com/mycompany/myproduct/gui.parent/1.0-SNAPSHOT/maven-metadata.xml
Downloaded: http://artifactory.buildnet.mycompany.com/artifactory/libs-snapshot-local/com/mycompany/myproduct/gui.parent/1.0-SNAPSHOT/maven-metadata.xml (594 B at 3.3 KB/sec)

设置文件的内容是:

<settings>
  <servers>
    ... (only relevant for deploy)
  </servers>
  <mirrors>
    <mirror>
      <id>mycompany-remote-mirror</id>
      <name>mycompany remote repositories mirror</name>
      <url>http://artifactory.buildnet.mycompany.com/artifactory/remote-repos</url>
      <mirrorOf>*,!eclipse*,!mycompany-snapshots,!mycompany-releases</mirrorOf>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>mycompany-default</id>
      <repositories>
        <repository>
          <id>mycompany-snapshots</id>
          <name>MyCompany snapshots repository</name>
          <releases>
            <enabled>false</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://artifactory.buildnet.mycompany.com/artifactory/libs-snapshot-local</url>
          <layout>default</layout>
        </repository>
        <repository>
          <id>mycompany-releases</id>
          <name>MyCompany releases repository</name>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>warn</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>false</enabled>
            <updatePolicy>never</updatePolicy>
            <checksumPolicy>fail</checksumPolicy>
          </snapshots>
          <url>http://artifactory.buildnet.mycompany.com/artifactory/libs-release-local</url>
          <layout>default</layout>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>mycompany-default</activeProfile>
  </activeProfiles>
</settings>

这是父 POM(请注意,在我们的项目中,它与包含模块的主 POM 分开):

<project ...>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.mycompany.myproduct</groupId>
  <artifactId>gui.parent</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <properties>
    <product-id>MyProduct</product-id>
    <tycho.version>0.17.0</tycho.version>
    <tycho-extras.version>0.17.0</tycho-extras.version>
    <eclipse.version>juno</eclipse.version>
    <eclipse.repo>http://download.eclipse.org/releases/${eclipse-version}</eclipse.repo>
  </properties>

  <distributionManagement>
    ...
  </distributionManagement>

  <repositories>
    <repository>
      <id>eclipse</id>
      <url>${eclipse.repo}</url>
      <layout>p2</layout>
    </repository>
  </repositories>

  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-maven-plugin</artifactId>
      </plugin>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>target-platform-configuration</artifactId>
      </plugin>
      <plugin>
        <groupId>org.eclipse.tycho</groupId>
        <artifactId>tycho-source-plugin</artifactId>
      </plugin>
      <plugin>  
        <groupId>org.eclipse.tycho</groupId>  
        <artifactId>tycho-versions-plugin</artifactId>  
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-release-plugin</artifactId>
      </plugin>
    </plugins>

    <pluginManagement>
      <plugins>
        <!-- PARENT PLUGINS -->
        <plugin>
          <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>
            ...
          </configuration>
        </plugin>
        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-source-plugin</artifactId>
          <version>${tycho.version}</version>
          ...
        <plugin>  
          <groupId>org.eclipse.tycho</groupId>  
          <artifactId>tycho-versions-plugin</artifactId>  
          <version>${tycho.version}</version>
        </plugin>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-release-plugin</artifactId>
          <version>2.4.1</version>
        </plugin>
        <!-- END OF PARENT PLUGINS -->

        <!-- DEFAULT PLUGINS -->
        <plugin>
          <groupId>org.eclipse.tycho</groupId>
          <artifactId>tycho-compiler-plugin</artifactId>
          <version>${tycho.version}</version>
          <configuration>
            <compilerArguments>
              <inlineJSR/>
              <enableJavadoc/>
              <encoding>ISO-8859-1</encoding>
            </compilerArguments>
          </configuration>
        </plugin>
        <!-- END OF DEFAULT PLUGINS -->

        <!-- OTHER PLUGINS -->
        ... (maven-resources, tycho-surefire, tycho-p2, tycho-p2-director,
             tycho-p2-repository, ...)
        <!-- END OF OTHER PLUGINS -->
      </plugins>
    </pluginManagement>
  </build>
</project>

一个依赖他人的插件的POM.xml如下:

<project ...>
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.mycompany.myproduct</groupId>
    <artifactId>gui.parent</artifactId>
    <version>1.0-SNAPSHOT</version>
  </parent>
  <artifactId>com.mycompany.myproduct.gui.editors</artifactId>
  <version>1.8.15-SNAPSHOT</version>
  <packaging>eclipse-plugin</packaging>
</project>

同一个插件的 MANIFEST.MF 文件如下:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: MyProduct Editors Plug-in
Bundle-SymbolicName: com.mycompany.myproduct.gui.editors;singleton:=true
Bundle-Version: 1.8.15.qualifier
Bundle-Activator: com.mycompany.myproduct.gui.editors.Activator
Bundle-ActivationPolicy: lazy
Export-Package: com.mycompany.myproduct.gui.editors,
 com.mycompany.myproduct.gui.editors.logger,
 com.mycompany.myproduct.gui.editors.report
Bundle-Vendor: MyCompany
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.ui.workbench;bundle-version="3.104.0",
 org.eclipse.core.runtime;bundle-version="3.8.0",
 org.eclipse.jface;bundle-version="3.8.0",
 com.mycompany.myproduct.preferences;bundle-version="1.8.15",
 com.mycompany.myproduct.gui.utils;bundle-version="1.8.15",
 org.eclipse.ui.workbench;bundle-version="3.104.0"
4

2 回答 2

9

Tycho 不会在 Maven 存储库中查找其依赖项(因为 Maven 存储库没有足够的元数据来解析 OSGi 清单中指定的依赖项)。相反,Tycho 需要来自远程的工件的 p2 存储库。

因此,为了涵盖构建反应器部件的用例,您需要执行以下操作:

  • 让 CI 构建生成一个 p2 存储库,该存储库聚合来自反应器的所有工件,并在静态 URL 上发布该 p2 存储库。(最简单的解决方案是使用 Jenkins 作业并使用指向构建工作区的 URL。)
  • 在您的项目中创建一个配置文件,将 CI 构建 p2 存储库添加为 POM 中具有布局 p2 的存储库。

这样,即使您不同时构建其他模块,项目的工件也将成为模块目标平台的一部分。

于 2013-04-26T13:42:05.937 回答
1

我认为除了 maven 坐标之外,您只需要提供到父级的相对路径即可。如果没有相对路径,它仅在父 pom 至少已经在您的本地仓库中时才有效。

于 2013-04-26T12:59:10.013 回答