Need Apache commons-lang3 as dependency of an Eclipse plugin built with Tycho

I'm having one of those nights... I'm developing an Eclipse plugin using Tycho (the Maven extension), and at some point I wanted simply to use the class StringUtils from org.apache.commons. After some research, the only way that I could find is the following code in my pom.xml parent file:

  <dependencies>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>
  </dependencies>

  <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>
          <environments>
            <environment>
              ...

This didn't work, and any other solution that I tried didn't work either. I'm using Maven for the first time, so maybe I'm missing something (or a lot of things)... Does anyone have an idea? I'd be very thankful :o)

Answers


Your configuration looks correct. So if it doesn't work, you are probably missing the dependency declaration in the MANIFEST.MF. To do this, e.g. add Require-Bundle: org.apache.commons.lang3 in that file.

Background: A dependency in the POM doesn't automatically mean for Tycho that your bundle also automatically has this dependency. It only means that the artifact will be added to the target platform (given that pomDependencies=consider is configured and the artifact is an OSGi bundle - both is true in your case). Once it is in the target platform, it can be used to resolve the dependencies declared in your bundle's MANIFEST.MF.


It sounds like you need to "upgrade" to using a target platform to define your target.

How are you achieving this dependency in your development environment? If you are not using a target platform, you are inheriting whatever plug-ins are installed in your development (that is the default target platform).

Create Target Platform

First create a target platform. I recommend using the Target Platform Definition DSL and Generator to create and edit the target platform.

The tpd file will look something like this for orbit

target "name"

with source requirements

location "http://download.eclipse.org/tools/orbit/downloads/drops/R20150519210750/repository/" mars-orbit {
    org.apache.commons.lang3
}

location "http://download.eclipse.org/releases/mars" mars-release {
    org.eclipse.platform.feature.group
    org.eclipse.equinox.executable.feature.group
    org.eclipse.e4.rcp.feature.group
    org.eclipse.ui.trace
    org.eclipse.pde.feature.group
}

This example uses the already created OSGi bundles for third-parties. You can choose which release of orbit and browse all the available packages on the Orbit Site. You can also use auto-completion in the tpd editor.

Tycho Using Target Platform

Place the target file in a new plug-in. Name the target file the same as the plug-in. (e.g. com.example.releng.targetplatform.target is the name of the target file in this example.)

In this project, a pom that looks like this:

<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>
  <artifactId>com.example.releng.targetplatform</artifactId>
  <packaging>eclipse-target-definition</packaging>
  <parent>
    <groupId>com.example</groupId>
    <artifactId>com.example.releng</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <relativePath>../com.example.releng</relativePath>
  </parent>
</project>

You can configure (in your releng pom.xml) the target configuration like this:

<plugin>
    <groupId>org.eclipse.tycho</groupId>
    <artifactId>target-platform-configuration</artifactId>
    <version>${tycho-version}</version>
    <configuration>
        <target>
            <artifact>
                <groupId>eGui</groupId>
                <artifactId>com.example.releng.targetplatform</artifactId>
                <version>1.0.0-SNAPSHOT</version>
            </artifact>
        </target>
    </configuration>
</plugin>
Tutorial

Have a look at Code & Me's excellent tutorial on Tycho, it goes into more detail and over many steps goes from new project to a complete Tycho.


Need Your Help

oracle subtract 2 dates then divide by count

sql oracle average date-difference

I am trying to do (date1 - date2)/ count(date1)

Naming conventions for private members of .NET types

c# .net struct class

Normally when I have a private field inside a class or a struct, I use camelCasing, so it would be obvious that it's indeed private when you see the name of it, but in some of my colleagues' C# cod...