12

eclipse-pluginパッケージを使ってTychoプロジェクトを作成しました。プロジェクトには、pom.xmlを介して指定されたいくつかの依存関係が含まれています。関連するpomセクションは次のとおりです。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tycho.version>0.15.0</tycho.version>
</properties>
<build>
    <sourceDirectory>src</sourceDirectory>
    <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>
                <pomDependencies>consider</pomDependencies>
                <environments>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>macosx</os>
                        <ws>cocoa</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
            </configuration>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>juno</id>
        <layout>p2</layout>
        <url>http://download.eclipse.org/releases/juno</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.release</id>
        <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/release</url>
    </repository>
    <repository>
        <id>com.springsource.repository.bundles.external</id>
        <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
        <url>http://repository.springsource.com/maven/bundles/external</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>com.springsource.org.testng</artifactId>
        <version>6.4.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guice</groupId>
        <artifactId>com.springsource.com.google.inject</artifactId>
        <version>2.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.aopalliance</groupId>
        <artifactId>com.springsource.org.aopalliance</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

そしてマニフェストは次のとおりです。

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Plugin-project-pure
Bundle-SymbolicName: plugin-project-pure
Bundle-Version: 1.0.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.eclipse.equinox.app,
 org.eclipse.uml2.uml;bundle-version="4.0.0",
 org.eclipse.uml2.uml.resources;bundle-version="4.0.0",
 org.junit;bundle-version="4.10.0",
 com.springsource.org.testng;bundle-version="[6.4.0,6.4.0]"

org.testng.annotationsプロジェクトは、コンパイル中に依存関係が含まれていることをテストするためにfromのアノテーションを使用するデフォルトパッケージのクラスのみで構成されています。

Maven 3.0.4を使用してコマンドラインでプロジェクトをビルドしている場合、すべてが正常に機能します。プロジェクトをEclipseJunoにインポートした後、複数のエラーが発生します。最も重要なものはマニフェストにあり、バンドルcom.springsource.org.testngを解決できないことを示しています。アノテーションをインポートできないため、クラスにコンパイルエラーもあります。プロジェクトにはMavenNatureが構成されています。Eclipse Junoがpomの依存関係も考慮するように、何かが足りませんか?

4

3 に答える 3

11

プロジェクトのビルドを 2 つの部分に分割することで、この問題を回避できます。

  • まず、POM の依存関係を p2 リポジトリに集約します。eclipse-featureこれにはとeclipse-repositoryモジュールに加えて、POM の依存関係を一覧表示して構成する別の親 POM が必要ですpomDependencies=consider
  • 2 番目のビルドで、最初のビルドの p2 リポジトリをターゲット プラットフォームに追加します。たとえばjar:file:、ローカル Maven リポジトリのビルド結果を指す URL を使用します。

次に、Eclipse でターゲット プラットフォームを構成して、最初のビルドから p2 リポジトリを含めることもできます (現在の構成方法によって異なります)。Eclipseと Tycho の両方でターゲット プラットフォームとして使用できる、いわゆるターゲット定義ファイルを使用すると、Tycho と Eclipse の間で最高の一貫性が得られます。

これらすべてを設定するのはかなりの労力であることは承知していますが、完全に機能するより良い解決策はありません。

于 2012-09-18T17:44:57.887 に答える
10

maven-RCP の問題の間に存在するすべての問題に対する最も洗練された解決策は、 p2-maven-plugin. これらの問題の簡単な要約を次に示します (上記のリンクから抜粋)。

サードパーティの依存関係を Eclipse RCP プロジェクトに追加するには、依存関係が P2 更新サイトに存在する必要があります。

Eclipse (およびその他のプロバイダー) は一連の公開更新サイトを提供していますが、明らかに、人気があり公開されているすべての依存関係がそこにあるわけではありません (これが問題番号 1 です)。

Eclipse RCP は OSGi 環境であるため、依存関係を p2 更新サイトに追加するには、依存関係を OSGi バンドルにする必要があります (これが問題番号 2 です)。

すべてのアーティファクトは OSGi バンドルである必要がありますが、必ずしもバンドルであるとは限らず、P2 サイトに配置する必要がありますが、そのサイトはありません。それではどのように進めますか?

それほど難しくありません。Peter Kriens によって作成された 'bnd' ツールがあり、jar をバンドルに変換できます。P2 サイトを生成できる Eclipse RCP によって提供される便利なツールもあります (面倒で苦痛な方法ではありますが)。どちらのツールも、すべての jar/bundle がローカル フォルダーにあることを前提としています。つまり、手動でダウンロードする必要があります。Maven を使用して少し自動化することもできますが、Maven が依存関係ツリーを計算する方法には大きな違いがあり、これは OSGi の方法と常に互換性があるわけではありません (これが問題番号 3 です)。もう少し詳しく説明しましょう。

すべての maven 依存関係を解決し、すべての非 OSGi をバンドルに変換し、それらから p2 サイトを生成する pom パッケージ化されたプロジェクトを定義できます。

以下は、slf4j-log4j12 (slf4j と log4j v1.2 の両方に暗黙的に依存する) への依存関係を含む完全な最小限の pom ファイルです。

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>me.berezovskiy.project</groupId>
  <artifactId>p2</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <build>
    <plugins>
      <plugin>
        <groupId>org.reficio</groupId>
        <artifactId>p2-maven-plugin</artifactId>
        <version>1.1.1-SNAPSHOT</version>
        <executions>
          <execution>
            <id>default-cli</id>
            <configuration>
              <artifacts>
                <artifact>
                  <id>org.slf4j:slf4j-log4j12:1.7.7</id>
                </artifact>
              </artifacts>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.1.12.v20130726</version>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <webAppSourceDirectory>${basedir}/target/repository/</webAppSourceDirectory>
          <webApp>
            <contextPath>/site</contextPath>
          </webApp>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <pluginRepositories>
    <pluginRepository>
      <id>reficio</id>
      <url>http://repo.reficio.org/maven/</url>
    </pluginRepository>
  </pluginRepositories>
</project>

PS私は通常、古い回答済みの質問への回答を投稿しませんが、私の場合、この問題をクリーンでエレガントな方法で解決するのに非常に時間がかかったので、それについて書くことにしました. さらに、このソリューションは 2013 年後半に登場しました。

于 2014-07-16T09:47:23.127 に答える
6

コマンドラインから、pom.xmlが配置されているフォルダーに移動します。

を実行しますmvn eclipse:eclipse

これにより、有効なEclipseプロジェクトが構築されます。

于 2012-09-18T13:16:48.633 に答える