I'm trying to run jUnit tests for an Eclipse RCP application with Tycho.
For that I created a simple jUnit test, that runs when I click on Run as > jUnit-Test. But when I want to run it with mvn test, it doesn't find jUnit.
I read in the Internet that I have to add jUnit to the Build-Path. -> I already did that. Furthermore I read that I have to add jUnit as a require-bundle in my Manifest.mf file. But there is the problem!! I get the error: Bundle 'org.junit' canot be resolved.
My MANIFEST.MF file looks like this:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Tests
Bundle-SymbolicName: myPackageName
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: myCompany
Fragment-Host: thePackageWhereTestesPluginIs
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.junit
Where is my mistake? When I take org.junit4 it cannot be resolved either...
Thank you!
Update:
Now I use instead of require-bundle:
Import-package: org.junit4
(or org.junit, its' behavior is the same) and it can be resolved in the manifest.mf file. But when I run it, I get the following error:
[ERROR] -> [Help 1]
org.apache.maven.InternalErrorException: Internal error: java.lang.RuntimeException: org.osgi.framework.BundleException: Bundle myTestBundle cannot be resolved
Resolution errors:
Bundle myTestBundle - Missing Constraint: Import-Package: org.junit4; version="0.0.0"
How can I solve this?
Thank you!!
My pom file of the test bundle:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>myProject.tycho.master</artifactId>
<groupId>myProject</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../myProject.tycho.master/pom.xml</relativePath>
</parent>
<groupId>myProject</groupId>
<artifactId>myProject.myTestBundle</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.1</version>
</dependency>
</dependencies>
</project>
The parent pom:
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>myProject</groupId>
<artifactId>myProject.tycho.master</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.17.0</tycho.version>
</properties>
<modules>
<module>../myProject.myTestBundle</module>
</modules>
<repositories>
<!-- configure p2 repository to resolve against -->
<repository>
<id>Repository1</id>
<layout>p2</layout>
<url>url-to-a-p2-site-on-my-server</url>
</repository>
</repositories>
<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>
<resolver>p2</resolver>
<pomDependencies>consider</pomDependencies>
<target>
<artifact>
<groupId>myGroupId</groupId>
<artifactId>myGroupId.target</artifactId>
<classifier>targetPlatform</classifier>
</artifact>
</target>
<environments>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
</environments>
<ignoreTychoRepositories>false</ignoreTychoRepositories>
</configuration>
</plugin>
</plugins>
</build>
</project>
Update:
I think I resolved the problem!
I added jUnit to my p2 Update sites and now I don't get any errors!
I fixed my problem by adding jUnit as a p2 Update site and used it in the Manifest.mf as:
Require-Bundle: org.junit; bundle-version = "4.11.0"
Related
Im having a problem with the spring-boot-maven-plugin whereby it is not including the dependent classes in the resulting jar file.
In the docs, it states that dependencies with scope provided will be included in the jar file, but I cant get it to include them.
I have a project with 2 sub-modules: model and restServer. In the model module, I want to use swagger to codegen based on an openApi input model. The resulting classes are put in a jar file: model/target/rest-model-0.0.1-SNAPSHOT.jar.
In the restServer module, I have the Spring RestController and Application java code, and want to "pull in" the model classes into the resulting jar file: restServer/target/rest-server-0.0.1-SNAPSHOT.jar with the spring-boot-maven-plugin builder, but its not including anything from the model sub-module.
The entire project structure and pom files are listed below.
How can I get the spring-boot-maven-plugin to pull in the class files from the model sub-module, effectively creating a "fat" self-contained jar?
Project Structure
project-root/
pom.xml # parent pom
model/
pom.xml
src/main/openApi/model.json
target/
generated-sources/* (package: com.me.rest.model.*)
rest-model-0.0.1-SNAPSHOT.jar
restServer/
pom.xml
src/main/java/com/me/rest/
controller/Controller.java
Application.java
Parent pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
<groupId>com.me</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rest</name>
<packaging>pom</packaging>
<description>Swagger codegen for Spring Rest Server sandbox project</description>
<scm>
<connection>scm:git:git#github.com:swagger-api/swagger-codegen.git</connection>
<developerConnection>scm:git:git#github.com:swagger-api/swagger-codegen.git</developerConnection>
<url>https://github.com/swagger-api/swagger-codegen</url>
</scm>
<prerequisites>
<maven>2.2.0</maven>
</prerequisites>
<modules>
<module>model</module>
<module>restServer</module>
</modules>
</project>
model/pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies> ... </dependencies>
<build>
<plugins>
<!-- Swagger codegen plugin -->
<plugin>
<groupId>io.swagger</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration> ... </configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
restServer/pom.xml
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.kontron</groupId>
<artifactId>rest-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>rest-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>2.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.kontron</groupId>
<artifactId>rest-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>provided</scope> <!-- Notice scope is provided -->
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.1.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Update: adding resulting META-INF/MANIFEST.MF:
Manifest-Version: 1.0
Implementation-Title: rest-server
Implementation-Version: 0.0.1-SNAPSHOT
Built-By: bjohnson
Implementation-Vendor-Id: com.me
Spring-Boot-Version: 2.1.2.RELEASE
Main-Class: org.springframework.boot.loader.JarLauncher
Start-Class: com.me.rest.Application
Spring-Boot-Classes: BOOT-INF/classes/
Spring-Boot-Lib: BOOT-INF/lib/
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_144
Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo
ot-starter-parent/rest-parent/rest-server
The dependencies are placed in BOOT-INF\lib\ of the repackaged JAR file.
This path will be added to the classpath of you Spring Boot Application.
I am using 'Tycho'(Maven) for eclipse plugin project build .
I am getting the error :
Unresolveable build extension: Plugin org.eclipse.tycho:tycho-maven-plugin:0.22.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.eclipse.tycho:tycho-maven-plugin:jar:0.22.0: Could not transfer artifact org.eclipse.tycho:tycho-maven-plugin:pom:0.22.0 from/to central (https://repo.maven.apache.org/maven2): connect timed out -> [Help 2]
POM.xml file looks like
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tycho_example</groupId>
<artifactId>com.codeandme.tycho.plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.22.0</tycho.version>
</properties>
<repositories>
<!-- add Mars repository to resolve dependencies -->
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/mars/</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>
</plugins>
</build>
</project>
I am sure your problem is solved. However, for others who have the same error,the solution is :
Include the tag <pluginManagement> in parent pom.xml file. <pluginManagement> is only a way to share the same plugin configuration across all your project modules.Here is sample parent pom.xml file
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>${tycho-groupid}</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>${tycho-groupid}</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<resolver>p2</resolver>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
This can't be solved by adding
<PluginManagement>
...
</PluginManagement>
It's simply because the eclipse m2e connector can't download these plugins from a repo.
Open your Maven Console and see if it prints something after you saved your pom.xml
it probably will tell you, that it couldn't acces the repo or no maven settings.xml is assigned to the m2e connector.
Find the full Solution here:
Maven: unresolvable build extension
I am very new to tycho. I changed my existing e4 RCP application for Tycho Maven based build. While my normal export from Eclipse IDE works fine, with Tycho I am getting following error.
Cannot complete the install because one or more required items could not be found.
Software being installed: Chartcube Database Connector 1.0.0.201601060933 (**.**.demo.product 1.0.0.201601060933)
Missing requirement: toolingwin32.win32.x86_64org.eclipse.equinox.p2.reconciler.dropins 1.0.0.201601060933 requires 'bundle org.eclipse.equinox.p2.reconciler.dropins 1.1.300.v20150423-1455' but it could not be found
Cannot satisfy dependency:
From: **** ****. 1.0.0.201601060933 (com.*****.*****.demo.product 1.0.0.201601060933)
To: toolingcom.toolingcom.****.****.demo.product.configuration [1.0.0.201601060933]
Cannot satisfy dependency:
From: toolingcom.****.****.demo.product.configuration 1.0.0.201601060933
To: toolingwin32.win32.x86_64org.eclipse.equinox.p2.reconciler.dropins [1.0.0.201601060933]
Application failed, log file location: /home/****/.log
My aggreegator pom file is as :
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>ChartCubeDemo</module>
</modules>
<properties>
<tycho.version>0.24.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mars-repo.url>http://download.eclipse.org/releases/mars</mars-repo.url>
<nebula-repo.url>http://download.eclipse.org/nattable/releases/1.3.0/repository/</nebula-repo.url>
<orbit-repo.url>http://download.eclipse.org/tools/orbit/downloads/drops/R20150124073747/repository/</orbit-repo.url>
</properties>
<repositories>
<repository>
<id>mars</id>
<url>${mars-repo.url}</url>
<layout>p2</layout>
</repository>
<repository>
<id>nebula</id>
<url>${nebula-repo.url}</url>
<layout>p2</layout>
</repository>
<repository>
<id>orbit</id>
<url>${orbit-repo.url}</url>
<layout>p2</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>0.24.0</version>
<configuration>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</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>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.24.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
And my product file is :
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>group</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-repository</packaging>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-director-plugin</artifactId>
<version>0.24.0</version>
<configuration>
<formats>
<win32>zip</win32>
<linux>tar.gz</linux>
<macosx>tar.gz</macosx>
</formats>
</configuration>
<executions>
<execution>
<id>materialize-products</id>
<goals>
<goal>materialize-products</goal>
</goals>
</execution>
<execution>
<id>archive-products</id>
<goals>
<goal>archive-products</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is there something I am missing? Should I need to add anything extra in these POM files?
Also My .Product file has following configurations :
<configurations>
<plugin id="org.eclipse.core.runtime" autoStart="true" startLevel="0" />
<plugin id="org.eclipse.equinox.common" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.ds" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.event" autoStart="true" startLevel="2" />
<plugin id="org.eclipse.equinox.p2.reconciler.dropins" autoStart="true" startLevel="0" />
<plugin id="org.eclipse.equinox.simpleconfigurator" autoStart="true" startLevel="1" />
<plugin id="org.eclipse.update.configurator" autoStart="true" startLevel="4" />
</configurations>
You are showing the start configuration of your product, but not the contents of your product. I assume the org.eclipse.equinox.p2.reconciler.dropins plugin is not part of your product. If you have a feature based product you need to ensure that this plugin is also in one of the features.
Another option would be to remove it from your launch configuration. I assume it was added by adding the defaults via button, but it should not be necessary.
I want to do the simplest Maven build with Tycho, but couldn't get it working. My project has only one pom.xml file, there are no parent or sibling POMs.
When I run mvn clean install I get lots of compilation errors which entries such as:
[ERROR] /dir/file.java:[8,33] package org.eclipse.core.commands does not exist
This is how my POM file looks like:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<name>myartifact</name>
<description>Maven stuff</description>
<properties>
<tycho.version>0.20.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<luna-repo.url>http://download.eclipse.org/releases/luna</luna-repo.url>
<kepler-repo.url>http://download.eclipse.org/releases/kepler</kepler-repo.url>
</properties>
<repositories>
<repository>
<id>luna</id>
<url>${luna-repo.url}</url>
<layout>p2</layout>
</repository>
<repository>
<id>kepler</id>
<url>${kepler-repo.url}</url>
<layout>p2</layout>
</repository>
</repositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<pde>true</pde>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<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>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
This is how my manifest file looks like:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: pluginname
Bundle-SymbolicName: pluginname;singleton:=true
Bundle-Version: 1.0.0.SNAPSHOT
Bundle-Activator: com.mygroup.pluginname.ui.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.ui.ide,
org.apache.commons.io;bundle-version="2.0.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
I don't really know what I am missing here.
Your project doesn't specify a packaging type, so it defaults to jar. For jar projects, Tycho doesn't do anything, so all your otherwise correct configuration has no effect.
To activate Tycho, you need to add the configuration
<packaging>eclipse-plugin</packaging>
Then, Tycho will resolve the build class path according to the dependencies you have declared in the OSGi manifest.
Note that Tycho doesn't use the maven-compiler-plugin, so after activating Tycho this configuration has no effect. Also, I have no experience with the maven-eclipse-plugin in combination with Tycho. Instead of that plugin, I would recommend to use M2Eclipse for importing the project in Eclipse.
You need to add a dependency for the set of libraries you are using in your source code.
Maven isn't being told to obtain or manage them, so Eclipse doesn't know they exist. When you are trying to import them in your source code and compile, it's generating the error you are seeing.
Ex:
<dependencies>
...
<dependency>
<groupId>org.eclipse.core</groupId>
<artifactId>commands</artifactId>
<version>3.3.0-I20070605-0010</version>
</dependency>
...
</dependencies>
See the eclipse repository for the info required for other libraries.
EDIT: To fix your SWT compilation error, follow the steps shown on the SWT-repo project's webpage. An example for the win32 Intel x86/x64 architecture:
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
<version>4.4</version>
</dependency>
Change yours based on your platform.
I'm trying to build my eclipse-plugin using tycho.
My package com.mycompany.math requires org.apache.commons.math-1.2.0, which is installed in my p2-repository.
The dependency is defined in the MANIFEST.MF of org.mycompany.math:
Require-Bundle: org.apache.commons.math;bundle-version="1.2.0",
During my build, i get the error-message that the org.apache.commons.math-classes could not resolved.
Before the build start's, maven/tycho downloaded the 2.1.0-version.
So, my question is, why maven/tycho download's 2.1.0, when i defined in the MANIFEST.MF that i use 1.2.0.
You can see in my parent pom.xml that i defined three p2-repository's. The last one, contains my required 1.2.0-version.
My parent 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>
And my 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>
The problem is that your Require-Bundle statement is too general:
With Require-Bundle: org.apache.commons.math;bundle-version="1.2.0" you actually specify that you need the math bundle in version 1.2.0 or any later version.
You should specify that you only want 1.2.0 or compatible versions. This can be done with Require-Bundle: org.apache.commons.math;bundle-version="[1.2.0,2.0.0)". This statement prevents that your bundle will be wired against the (apparently incompatible) 2.1 version of the math bundle at runtime (which is also important!), and it will probably also fix your build problem.
Tycho may still resolve against a higher 1.x version of the math bundle for building, if such a version is present in the target platform (i.e. in your case any of the configured p2 repository or amongst the POM dependencies). If this is the case, but you want to enforce that the 1.2 version is used in the build, you need to control the content of your target platform. (The Maven <dependencyManagement> is not enough, because it doesn't have an effect on the p2 repositories you configured.) You can do this by specifying filters in Tycho's target platform configuration:
<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>