Search code examples
maventycho

Classes from required Eclipse plugins are missing when building with Maven


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.


Solution

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