I want to deploy a Maven Dependency package (Spring Boot Library Project) in GitLab, so that I could use this library as a dependency in other projects.
Now I went through the Gitlab Package docs and below are the changes I made as per docs.
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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.one</groupId>
<artifactId>common</artifactId>
<version>${env.CI_COMMIT_TAG}</version>
<name>common</name>
<description>Common Library</description>
<properties>
<java.version>11</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>3.1.5</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
<optional>true</optional>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<!--suppress UnresolvedMavenProperty -->
<url>${env.CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<!--suppress UnresolvedMavenProperty -->
<url>${env.CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<!--suppress UnresolvedMavenProperty -->
<url>${env.CI_API_V4_URL}/projects/${env.CI_PROJECT_ID}/packages/maven</url>
</snapshotRepository>
</distributionManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I also created ci_settings.xml file
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
For CI/CD , added .gitlab-ci.yml file
image: maven:latest
stages:
- deploy
variables:
MAVEN_OPTS: "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
workflow:
rules:
- if: $CI_COMMIT_TAG
deploy-job:
stage: deploy
environment: production
script:
- mvn deploy -s ci_settings.xml
- echo "Application successfully deployed."
Now after creating a new tag 0.0.1 in Gitlab Repository, the pipeline is initiated and package deployed.
The problem is when adding the package dependency
<dependency>
<groupId>com.example.one</groupId>
<artifactId>common</artifactId>
<version>0.0.1</version>
</dependency>
in another project within same group, I get below error
com.example.one:common:jar:0.0.1 was not found in https://repo.maven.apache.org/maven2 during a previous
attempt. This failure was cached in the local repository and resolution is not reattempted until
the update interval of central has elapsed or updates are forced
I also tried adding <repositories> tag in target project, but then I get different error
com.example.one:common:jar:0.0.1 was not found in https://gitlab.com/api/v4/projects/XXXXXX/packages/maven
during a previous attempt. This failure was cached in the local repository and resolution is not
reattempted until the update interval of gitlab-maven has elapsed or updates are forced
I am not sure what I am doing wrong.
I got the solution. Since the package is in a private repository , I was not authenticating the gitlab-maven dependency call.
I added the servers with deploy-token of gitlab in target project maven settings.xml
Related
As it says in the title, the Nexus3 send a wrong url to download artifact.
I am getting the following error on the console.
[INFO] Scanning for projects...
Downloading from maven-group: http://localhost:8081/repository/backend-group/br/edu/sig/backend/0.0.1-SNAPSHOT/maven-metadata.xml
[WARNING] Could not transfer metadata br.edu.sig:backend:0.0.1-SNAPSHOT/maven-metadata.xml from/to maven-group (http://localhost:8081/repository/backend-group/): Transfer failed for http://localhost:8081/repository/backend-group/br/edu/sig/backend/0.0.1-SNAPSHOT/maven-metadata.xml
Downloading from maven-group: http://localhost:8081/repository/backend-group/br/edu/sig/backend/0.0.1-SNAPSHOT/backend-0.0.1-SNAPSHOT.pom
I understand by this error that maven tries to download the xml shown with the blue arrow in the figure below, it cannot, right afterwards it alerts that it did not have access to the "backend-group" repository, but even so it tries to download the pom with the arrow black, but the url has been ignoring the red arrow packet, consequently fails to download because there is a 404 error there.
I believe I may be doing something wrong in the settings.xml, but I don't know what.
Note: the nexus is in a docker container at the url localhost:8081.
docker-compose:
version: '3.7'
services:
nexus:
container_name: sighepr-nexus
image: sonatype/nexus3:latest
restart: always
ports:
- 8081:8081
volumes:
- ./nexus3:/nexus-data
.../.m2/settings.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus-group</id>
<name>nexus-group</name>
<url>http://localhost:8081/repository/backend-group/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
Backend Pom
<modelVersion>4.0.0</modelVersion>
<name>backend</name>
<groupId>br.edu.sig</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<distributionManagement>
<snapshotRepository>
<id>nexus-snapshots</id>
<url>http://localhost:8081/repository/backend-snapshots/</url>
</snapshotRepository>
<repository>
<id>nexus-releases</id>
<url>http://localhost:8081/repository/backend-releases/</url>
</repository>
</distributionManagement>
Microservice pom
<parent>
<groupId>br.edu.sig</groupId>
<artifactId>backend</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath> <!-- lookup parent from repository -->
</parent>
<modelVersion>4.0.0</modelVersion>
<name>authentication</name>
<artifactId>authentication</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<finalName>authentication</finalName>
</build>
<repositories>
<repository>
<id>maven-group</id>
<url>http://localhost:8081/repository/backend-group/</url>
</repository>
</repositories>
I am not familiar with Tomcat, but I followed a tutorial. Everything run well until I launched the maven clean package.
The output gives me the following error :
[INFO] Internal error in the plugin manager executing goal 'org.apache.maven.plugins:maven-surefire-plugin:2.10:test': Unable to load the mojo 'org.apache.maven.plugins:maven-surefire-plugin:2.10:test' in the plugin 'org.apache.maven.plugins:maven-surefire-plugin'. A required class is missing: org/apache/maven/surefire/util/NestedRuntimeException
org.apache.maven.surefire.util.NestedRuntimeException
I have checked on the net and it seems this error is common, but none of the methods indicated worked : I have rm -Rf the .m2/repository/org/
My pom.xml is as follows :
<?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>
<groupId>sso.mydomain.com</groupId>
<artifactId>local-cas</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>cas</warName>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jasig.cas</groupId>
<artifactId>cas-server-webapp</artifactId>
<version>${cas.version}</version>
<type>war</type>
<scope>runtime</scope>
</dependency>
</dependencies>
<properties>
<cas.version>3.5.2</cas.version>
</properties>
<repositories>
<repository>
<id>ja-sig</id>
<url>http://oss.sonatype.org/content/repositories/releases/ </url>
</repository>
</repositories>
My conf : ubuntu, maven 2.2.1
I have spent an hour in this. any idea ?
I have created a working maven archetype for a Vaadin/Hibernate/Spring project. I am able to install this archetype to my local repository and use it to generate new maven projects.
Now I want to deploy the archetype to my companies internal repository, so it might be used by other developers. However, when I run mvn deploy I recieve the following error message:
[ERROR] Failed to execute goal org.apache.maven.plugins:
maven-deploy-plugin:2.7:deploy (default-deploy) on project
vaadin-hibernate-archetype: Failed to deploy artifacts/metadata:
No connector available to access repository maven.planet-ic.de
(maven.planet-ic.de/planet-ic-releases) of type default using the
available factories WagonRepositoryConnectorFactory -> [Help 1]
What is the connector that I am missing?
EDIT: I am not asking for someone to solve my problem, just some insight as to what the 'connector' is.
Here is my pom.xml if it should be of interest:
<?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>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<groupId>de.planetic.maven.archetype.vaadin</groupId>
<artifactId>vaadin-hibernate-archetype</artifactId>
<version>1.1.0</version>
<packaging>jar</packaging>
<inceptionYear>2013</inceptionYear>
<description>
This archetype generates a Vaadin application for use with Hibernate, and to be deployed to a Tomcat 7 server. It may also work with other Tomcat versions and other servers.
</description>
<developers>
<developer>
<name>Maximilian Friedersdorff</name>
<email>max.friedersdorff#planet-ic.de</email>
</developer>
</developers>
<scm>
<connection>scm:svn:http://subversion.planet-ic.de/internal/maven/archetype/pinnwand-webapp/tags/pinnwand-webapp-archetype-1.1.0</connection>
<developerConnection>scm:svn:http://subversion.planet-ic.de/internal/maven/archetype/pinnwand-webapp/tags/pinnwand-webapp-archetype-1.1.0</developerConnection>
<url>http://subversion.planet-ic.de/internal/maven/archetype/pinnwand-webapp/tags/pinnwand-webapp-archetype-1.1.0</url>
</scm>
<distributionManagement>
<repository>
<id>maven.planet-ic.de</id>
<name>planet-ic-releases</name>
<url>maven.planet-ic.de/planet-ic-releases</url>
</repository>
<snapshotRepository>
<id>maven.planet-ic.de</id>
<name>planet-ic-snapshots</name>
<url>http://maven.planet-ic.de/planet-ic-snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</pluginManagement>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</extension>
</extensions>
</build>
</project>
Depending on the maven repository you are trying to deploy to there are various methods available to upload your artifacts.
These methods are implemented using Maven Wagon connectors for different transport protocols (e.g. ssh,dav etc.), this is the term you are looking for.
Apache Maven Guide to using Extensions gives you an introduction on how to add connectors to your setup.
In the following line:
<url>maven.planet-ic.de/planet-ic-releases</url>
You need to add prefix of "file://", because you need to tell maven you are using file connector not ftp, http or something else.
And you'd better to use relative path there. For example:
<url>file://${project.basedir}/maven.planet-ic.de/planet-ic-releases/</url>
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</extension>
</extensions>
</build>
<distributionManagement>
<repository>
<id>remoteserver</id>
<name>MyCompany Repository</name>
<url>scp://server/path/repo</url>
</repository>
In case it helps others, adding the following to the pom.xml got it working for me
<build>
<extensions>
<extension>
<groupId>org.springframework.build</groupId>
<artifactId>aws-maven</artifactId>
<version>5.0.0.RELEASE</version>
</extension>
</extensions>
</build>
I have a multi-module maven project that I can't get to compile. I have a Nexus repository sitting on my local network, and it is working (IntelliJ Idea is able to resolve my dependencies which reside only in that repository), and I am building through Jetbrains TeamCity. I am fairly certain that TeamCity is working since several other build configurations I have set up still work (using the same settings.xml). I am a bit of a loss for what could be causing the issue. Here are my pom files:
Parent 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.product.plugins</groupId>
<artifactId>plugin-parent</artifactId>
<version>1.2-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>product-wireless-plugin</module>
<module>product-paging-plugin</module>
</modules>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<pluginRepositories>
<pluginRepository>
<id>autoincrement-versions-maven-plugin</id>
<name>autoincrement-versions-maven-plugin</name>
<url>http://autoincrement-versions-maven-plugin.googlecode.com/svn/repo</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>autoincrement-versions-maven-plugin</artifactId>
<version>2.0-SNAPSHOT</version>
<executions>
<execution>
<id>update-pom-versions</id>
<goals>
<goal>increment</goal>
<goal>commit</goal>
</goals>
<phase>compile</phase>
<configuration>
<autoIncrementVersion>true</autoIncrementVersion>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
</plugins>
</build>
</project>
product-wireless 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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>plugin-parent</artifactId>
<groupId>com.company.product.plugins</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.product.plugins</groupId>
<artifactId>product-wireless-plugin</artifactId>
<version>0.1.2</version>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>product-common</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
</project>
product-paging 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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>plugin-parent</artifactId>
<groupId>com.company.product.plugins</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.product.plugins</groupId>
<artifactId>product-paging-plugin</artifactId>
<version>0.1.2</version>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<url>http://192.168.2.192:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>product-common</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
</project>
And the error I am getting is:
com.company.product.plugins:product-wireless-plugin
[13:54:16][com.company.product.plugins:product-wireless-plugin] Importing data from 'C:/TeamCity/buildAgent/work/40ac813105cf8bd7/product-wireless-plugin/target/surefire-reports/TEST-*.xml' with 'surefire' processor
[13:54:16][com.company.product.plugins:product-wireless-plugin] Surefire report watcher
[13:54:16][com.company.product.plugins:product-wireless-plugin] Downloading: repolocation/nexus/content/groups/public/com/company/product/product-parent/0.9.0/product-parent-0.9.0.pom
[13:54:16][com.company.product.plugins:product-wireless-plugin] Failed to execute goal on project product-wireless-plugin: Could not resolve dependencies for project com.company.product.plugins:product-wireless-plugin:jar:0.1.2: Failed to collect dependencies for [com.company.product:product-common:jar:0.9.1 (compile)]
I am at quite a loss while trying to debug this... does anyone have any suggestions?
There are several approaches / tools for troubleshooting this sort of problem.
For this "could not resolve dependencies" error, there is almost always a more detailed error message and/or stacktrace earlier in the build log. Maven logs are actually extremely verbose, to the point of having to search for the "root" error message several screens up from the build failure.
Re-run the build with the -X flag. Here is documentation of Maven command line switches
Another option is to use mvn dependency:tree to inspect the full graph of transitive dependencies. mvn help:effective-pom is another useful tool that prints out the pom.xml after considering your settings.xml, any active profiles, etc. Likewise mvn help:active-profiles
There are many problems in your multi-module build. The most important one is that you define a dependency:
<dependencies>
<dependency>
<groupId>com.company.product</groupId>
<artifactId>product-common</artifactId>
<version>0.9.1</version>
</dependency>
</dependencies>
which seemed either not be existing in a repository or you have not access to the repository which contains it or your download has failed based on whatever reason (can't guess!). Are you using a repository manager like Artifactory, Nexus, Archiva? If not i recommend to start using one.
Apart from that you are using different versions for parent and the module in wireless-module:
<parent>
<artifactId>plugin-parent</artifactId>
<groupId>com.company.product.plugins</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.product.plugins</groupId>
<artifactId>product-wireless-plugin</artifactId>
<version>0.1.2</version>
A multi module build should define the version only via the parent and not within the artifact which means the above should look like this:
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>plugin-parent</artifactId>
<groupId>com.company.product.plugins</groupId>
<version>1.2-SNAPSHOT</version>
</parent>
<groupId>com.company.product.plugins</groupId>
<artifactId>product-wireless-plugin</artifactId>
The module should not define a version itself, cause it will inherit it from the parent. Furthermore you can see that you have a module which defines a release version (1.2) whereas the parent defines a SNAPSHOT version. An application/modules which are under development should define a version which is a SNAPSHOT version which means a thing like 1.2-SNAPSHOTetc.
The same applies accordingly for the definition of the distributionManagement. This should be defined only once in the parent of the project.
BTW. If you have several project the best is to define a company parent which contains some default definitions like distributionManagement, pluginManagement, dependencyManagement etc.
Ok, I have solved the problem thanks to input from #noahlz. After utilizing the -X flag to debug my build, I was finding that the parent pom of "product-common" (product-parent) could not be found. After browsing my Sonatype Nexus repository, I discovered that my build system was only publishing new versions of the parent pom when new modules were added to it. So, even though my parent pom was on version 0.9.0, the repository had the latest version as 0.6.1. I suppose the "product-common" library was compiling correctly because it had access to the parent pom (with the 0.9.0 version number) at compile time. Either way, changing the parent pom version in "product-common" to point to the most recent in the repository resolved my build issues with my plugins.
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>