开发者

Cannot resolve Mockito dependency in a Tycho project [duplicate]

This question already has an answer here: Closed 10 years ago.

Possible Duplicate:

How to reference mockito within tycho?

I am trying to get a test feature project building with Tycho, but it fails to resolve dependencies listed in my pom from the Maven central repository that is listed in my parent pom. Here is the relevant part from my parent 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>

and here my feature 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>

when I run mvn clean package on my feature project, I get the following:

[INFO] Adding repository http://download.eclipse.org/releases/helios/ [INFO] Adding repository http://download.eclipse.org/releases/helios/ [DEBUG] Added p2 repository helios (http://download.eclipse.org/releases/helios/ ) [DEBUG] Ignoring Maven repository central (http://repo1.maven.org/maven2)

and then my build fails, because my dependency cannot be resolved. Am I missing something? Is this because of the p2 resolver configured for target-platform-configuration?


Indeed it seems you are correct.

First, create a Target Definition file (.target) and put it inside a Maven project, see here for example target: https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/platform/indigo.target

You need to attach the .target file to the artifact, using the build helper:

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

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

Then, in the parent POM or the plug-in projects that use that target definition file, you need to configure the "target" of target-platform-configuration Maven plugin, for example:

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

(taken from https://github.com/eclipsesource/com.eclipsesource.tycho.aspectj.demo/blob/master/releng/pom.xml )

Then your project(s) should build very nicely using Tycho. :-) If your .target references remote p2 repositories and not already in the p2 bundle pool, the necessary artifacts will be downloaded automatically.

Good luck!

Known Issue:

[WARNING] Target location type: Profile is not supported

As of Tycho 0.12.0, It means the "Eclipse Installation" target source type cannot be used with Tycho (yet?), along with "Directory" and "Features".

Solution: Use the "Update Site" target source.

If you don't have yet an update site, here's to generate an update site from an Eclipse (or from any folder containing bundles, for that matter):

/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

Note:

  • change /opt/eclipse_rcp to your own Eclipse SDK installation
  • metadataRepository and artifactRepository is the folder where the new update site will be created
  • source is --you guessed it-- the folder/installation containing the original bundles
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜