5

可能重复:
如何在 tycho 中引用 mockito?

我正在尝试使用 Tycho 构建一个测试功能项目,但它无法从我的父 pom 中列出的 Maven 中央存储库中解决我的 pom 中列出的依赖项。这是我父母 pom 的相关部分:

    <properties>
            <tycho-version>0.12.0</tycho-version>
    </properties>

    <repositories>
            <repository>
                    <id>helios</id>
                    <layout>p2</layout>
                    <url>http://download.eclipse.org/releases/helios/</url>
            </repository>
    </repositories>

    <pluginRepositories>
            <pluginRepository>
                    <id>central</id>
                    <name>Maven Plugin Repository</name>
                    <url>http://repo1.maven.org/maven2</url>
                    <layout>default</layout>
                    <snapshots>
                            <enabled>false</enabled>
                    </snapshots>
                    <releases>
                            <updatePolicy>never</updatePolicy>
                    </releases>
            </pluginRepository>
    </pluginRepositories>

    <build>
            <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>

                                    <resolver>p2</resolver>

                                    <environments>
                                            <environment>
                                                    <os>linux</os>
                                                    <ws>gtk</ws>
                                                    <arch>x86_64</arch>
                                            </environment>
                                            <environment>
                                                    <os>win32</os>
                                                    <ws>win32</ws>
                                                    <arch>x86</arch>
                                            </environment>
                                    </environments>
                            </configuration>
                    </plugin>
            </plugins>
    </build>

这里是我的功能 pom:

    <modelVersion>4.0.0</modelVersion>
    <parent>
            <artifactId>parent</artifactId>
            <groupId>com.example</groupId>
            <version>1.0.0-SNAPSHOT</version>
    </parent>
    <groupId>com.example</groupId>
    <artifactId>com.example.testing.feature</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>eclipse-feature</packaging>

    <dependencyManagement>
            <dependencies>
                    <dependency>
                            <groupId>org.mockito</groupId>
                            <artifactId>mockito-all</artifactId>
                            <version>1.8.5</version>
                    </dependency>
            </dependencies>
    </dependencyManagement>

    <dependencies>
            <dependency>
                    <groupId>org.mockito</groupId>
                    <artifactId>mockito-all</artifactId>
            </dependency>
    </dependencies>

当我在我的功能项目上运行 mvn clean package 时,我得到以下信息:

[INFO] 添加存储库http://download.eclipse.org/releases/helios/ [INFO] 添加存储库http://download.eclipse.org/releases/helios/ [DEBUG] 添加 p2 存储库 helios ( http:// download.eclipse.org/releases/helios /)[调试]忽略 Maven 存储库中心(http://repo1.maven.org/maven2

然后我的构建失败,因为我的依赖无法解决。我错过了什么吗?这是因为为目标平台配置配置了 p2 解析器吗?

4

1 回答 1

7

确实,您似乎是对的。

首先,创建一个目标定义文件 (.target) 并将其放入 Maven 项目中,例如目标请参见此处:https ://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/platform /靛蓝.target

您需要使用构建助手将 .target 文件附加到工件:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>attach-artifacts</id>
            <phase>package</phase>
            <goals>
                <goal>attach-artifact</goal>
            </goals>
            <configuration>
                <artifacts>
                    <artifact>
                        <file>indigo.target</file>
                        <type>target</type>
                        <classifier>indigo</classifier>
                    </artifact>
                </artifacts>
            </configuration>
        </execution>
    </executions>
</plugin>

(来自https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/platform/pom.xml

然后,在父 POM 或使用该目标定义文件的插件项目中,需要配置目标平台配置 Maven 插件的“目标”,例如:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <resolver>p2</resolver>
        <ignoreTychoRepositories>true</ignoreTychoRepositories>
        <target>
            <artifact>
                <groupId>com.eclipsesource.sandbox.weaving.demo</groupId>
                <artifactId>com.eclipsesource.sandbox.weaving.demo.platform</artifactId>
                <version>0.1.0-SNAPSHOT</version>
                <classifier>indigo</classifier>
            </artifact>
        </target>
        <environments>
            <environment>
                <os>${build.os}</os>
                <ws>${build.ws}</ws>
                <arch>${build.arch}</arch>
            </environment>
        </environments>
    </configuration>
</plugin>

(取自https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/releng/pom.xml

那么你的项目应该使用 Tycho 构建得非常好。:-) 如果您的 .target 引用远程 p2 存储库并且尚未在 p2 捆绑池中,则将自动下载必要的工件。

祝你好运!

已知问题:

[WARNING] Target location type: Profile is not supported

从 Tycho 0.12.0 开始,这意味着“Eclipse 安装”目标源类型不能与 Tycho 一起使用(还没有?),以及“目录”和“功能”。

解决方案:使用“更新站点”目标源。

如果您还没有更新站点,这里是从 Eclipse(或任何包含捆绑包的文件夹,就此而言)生成更新站点:

/opt/eclipse_rcp/eclipse -consolelog -nosplash -verbose \
  -application org.eclipse.equinox.p2.publisher.FeaturesAndBundlesPublisher \
  -metadataRepository file:/home/ceefour/p2/bonita/ \
  -artifactRepository file:/home/ceefour/p2/bonita/ \
  -source /home/ceefour/BOS-5.5.1/studio/ \
  -publishArtifacts

笔记:

  • 将 /opt/eclipse_rcp 更改为您自己的 Eclipse SDK 安装
  • metadataRepository 和 artifactRepository 是创建新更新站点的文件夹
  • 源是——你猜对了——包含原始捆绑包的文件夹/安装
于 2011-07-16T16:45:51.807 回答