Why Tycho cannot resolve this simple dependency to SWT? - eclipse

I thought to have studied enough Maven + Tycho to configure at least a minimal target environment for a headless build, but still I am unable to make this small example work. I have three projects:
test, that contains
sub.ui and
sub.target
The test project has just a pom.xml that builds the two subprojects and whose only interesting part is the <pluginManagement> section:
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>target-platform</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</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>
<pomDependencies>wrapAsBundle</pomDependencies>
<target>
<artifact>
<groupId>${project.groupId}</groupId>
<artifactId>sub.target</artifactId>
<version>0.0.1-SNAPSHOT</version>
</artifact>
</target>
<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>
</pluginManagement>
</build>
...
verbose but quite straightforward (except perhaps for the lifecycle-mapping plugin, that however impacts only when building under Eclipse, and I want to build outside Eclipse). The sub.target project has a canonical pom.xml with just:
...
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
</plugin>
</plugins>
</build>
...
and a brief sub.target.target file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?>
<target includeMode="feature" name="Test" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<repository location="https://download.eclipse.org/releases/latest/"/>
<unit id="org.eclipse.equinox.p2.user.ui.feature.group" version="0.0.0"/>
</location>
</locations>
<targetJRE path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"/>
</target>
The sub.ui project is a small plugin project with a silly main that uses a SWT class:
package foo;
import org.eclipse.swt.widgets.Label;
public class Main {
public static void main(String[] args) {
Label l = new Label(null, 0);
}
}
and a MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Test UI
Bundle-SymbolicName: sub.ui;singleton:=true
Bundle-Version: 0.0.1.qualifier
Automatic-Module-Name: sub.ui
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.swt
Now, if I open a console and I mvn clear compile, Maven fails while building the Test UI plugin, and displays the errors:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:2.4.0:compile (default-compile) on project sub.ui: Compilation failure: Compilation failure:
[ERROR] /.../sub.ui/src/foo/Main.java:[3]
[ERROR] import org.eclipse.swt.widgets.Label;
[ERROR] ^^^^^^^^^^^
[ERROR] The import org.eclipse cannot be resolved
[ERROR] /.../sub.ui/src/foo/Main.java:[8]
[ERROR] Label l = new Label(null, 0);
[ERROR] ^^^^^
[ERROR] Label cannot be resolved to a type
[ERROR] /.../sub.ui/src/foo/Main.java:[8]
[ERROR] Label l = new Label(null, 0);
[ERROR] ^^^^^
[ERROR] Label cannot be resolved to a type
[ERROR] 3 problems (3 errors)
Apparently the build process does not link my code with the SWT version for my macos+cocoa platform, that is nevertheless listed among the plugins in the org.eclipse.equinox.p2.user.ui.feature.group. Strangely, if I launch Maven from Eclipse every now and then it links the right SWT library and completes the build process. What am I missing? How do I convince Tycho to use the information about my platform to consistently select the macos+cocoa SWT jar and link it to my code? I can share the complete example project on GitHub upon request if you cannot spot the mistake in the above code. Thank you for your patience.

Problem solved. Apparently the x86 platforms are no longer supported (the project I am working on is quite old). If we remove all the x86 <environment>s from the <pluginManagement> section of the main pom.xml file and leave only the x86_64 ones, everything works.

Related

maven cannot find javafx 11 when compiling an eclipse application

I have an eclipse application using javafx 11. For lack of better solution, I have javafx installed in /opt/javafx-sdk-11.0.2, the product definition contains --module-path /opt/javafx-sdk-11.0.2/lib/ --add-modules=javafx.controls as vm arguments, and .classpath contains these lines:
<classpathentry kind="lib" path="/opt/javafx-sdk-11.0.2/lib/javafx.base.jar"/>
<classpathentry kind="lib" path="/opt/javafx-sdk-11.0.2/lib/javafx.controls.jar"/>
<classpathentry kind="lib" path="/opt/javafx-sdk-11.0.2/lib/javafx.graphics.jar"/>
My pom.xml looks like this:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.rulez.magwas</groupId>
<artifactId>zenta3</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<groupId>zenta3-editor</groupId>
<artifactId>org.rulez.demokracia.zenta3.editor</artifactId>
<packaging>eclipse-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.openjfx.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>${jdk.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>ZentaApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
</dependencies>
</project>
The parent pom contains the properties, repos, and the following tycho build plugin configurations:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<archive>
<manifestEntries>
<Bundle-RequiredExecutionEnvironment>${jdk.full.version}</Bundle-RequiredExecutionEnvironment>
</manifestEntries>
</archive>
</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>
<executionEnvironment>${jdk.full.version}</executionEnvironment>
<dependency-resolution>
<extraRequirements>
<requirement>
<type>eclipse-plugin</type>
<id>org.eclipse.osgi.compatibility.state</id>
<versionRange>0.0.0</versionRange>
</requirement>
</extraRequirements>
</dependency-resolution>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</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>
jdk.version is 11, but tried it with 10 as well.
The weird thing about it that I remember I could compile it with maven, but cannot get it to compile now.
The error:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-compiler-plugin:1.4.0:compile (default-compile) on project org.rulez.demokracia.zenta3.editor: Compilation failure: Compilation failure:
[ERROR] /project/mag/Zenta/zenta3/ui/src/main/java/org/rulez/demokracia/zenta3/editor/parts/handles/DeleteElementHandlePart.java:
[ERROR] package org.rulez.demokracia.zenta3.editor.parts.handles;
[ERROR] ^
[ERROR] The type javafx.scene.paint.Color cannot be resolved. It is indirectly referenced from required .class files
[ERROR] /project/mag/Zenta/zenta3/ui/src/main/java/org/rulez/demokracia/zenta3/editor/parts/handles/DeleteElementHandlePart.java:[17]
[ERROR] public class DeleteElementHandlePart extends AbstractHandlePart<Group> {
[ERROR] ^^^^^
[ERROR] Group cannot be resolved to a type
[ERROR] 2 problems (2 errors)
Putting all the jars of javafx to the lib folder of the project, and listing them in classpath helped. But it seems more like a workaround than a solution, and I cannot figure out how to set the launch configuration of the product to be able actually launch it.

How to build a multiplatform Eclipse update site with Tycho

On my PDE/Tycho Eclipse environment I want to build a plugin of type eclipse-repository which contains 3 features each one for a specific platform.
The eclipse-repository plugin reads all its configuration from a parent plugin which content is the following:
<properties>
<tycho.version>0.26.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>neon</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/neon/</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>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</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>
</plugins>
</build>
When I try to build the eclpse-repository project I get an error:
[ERROR] Failed to execute goal org.eclipse.tycho:tycho-p2-repository-plugin:0.26.0:assemble-repository (default-assemble-repository) on project ... : Execution default-assemble-repository of goal org.eclipse.tycho:tycho-p2-repository-plugin:0.26.0:assemble-repository failed: Cannot resolve dependencies of MavenProject ...

Eclipse cannot find dependencies of a plugin built with Maven Tycho

I am using Maven Tycho to compile my projects which are structured like this :
- plugin1
- plugin2 (depends on plugin1)
- plugin3 (depends on plugin1 & 2)
- plugin4 (depends on plugin1)
- plugin5 (depends on plugin1 & 4)
- plugin6 (depends on all previous plugins)
- plugin7 (depends on all previous plugins)
{all these plugins are compiled as eclipse-plugin}
- feature1 (contains all previous plugins) {eclipse-feature}
- updatesite1 {eclipse-repository}
- generalproject (contains only the parent pom)
I compile this via Eclipse (maven install), everything works and i can access my local repository, and install my feature in the same Eclipse (through "Install new software").
The problem is when i try to install my feature to another instance of Eclipse, which refuse to install it with the error :
(Missing requirement: Acceleo Texts Module IDE Plug-in 1.0.0.201612161812 (myproject.acceleo.ui 1.0.0.201612161812) requires 'bundle org.eclipse.ocl 0.0.0' but it could not be found)
I know that this is a non satisfied requirement problem, but in Eclipse i checked "Contact all update sites during install to find required software", and my pom declares repositories containing all requirements, here is my parent pom :
<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>myproject.project</groupId>
<artifactId>myproject.general</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.23.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>Mars</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/mars/</url>
</repository>
<repository>
<id>Sirius</id>
<layout>p2</layout>
<url>http://download.eclipse.org/sirius/updates/releases/4.1.2/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>
<plugin>
<!-- enable tycho build extension -->
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho.version}</version>
<configuration>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>i386</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>
<modules>
<module>../myproject</module>
<module>../myproject.acceleo</module>
<module>../myproject.acceleo.ui</module>
<module>../myproject.design</module>
<module>../myproject.edit</module>
<module>../myproject.editor</module>
<module>../myproject.plugin</module>
<module>../myproject.project</module>
<module>../myproject.site</module>
</modules>
</project>
I cannot figure how to resolve this ? did i omit something in my procedure ?
Thank you.
I fell for the same thing. Tycho does not include all dependencies, even though that's normal and desired maven behaviour. As maven does not "see" tycho (so manifest-derived) dependencies, they are not included.
You can override this behaviour by setting to true:
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>
Probably the Eclipse installation where you want to install your feature does not have an update site configured that contains org.eclipse.ocl. This has nothing to do with your Maven build, as long as you didn't configure your feature to also contain the required bundles, which could also be done.

Installing eclipse plug-in built by Tycho

I want to install eclipse plug-in that was build with help of Tycho.
When I call mvn clean install Maven exits with SUCCESS, and in target directory there is .jar file.
I can't make Eclipse to work with this .jar, it says that file could not be found.
Am I missing something here? How to use my tycho built plug-in?
Here is my pom.xml:
<?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>com.my.example</groupId>
<artifactId>com.my.example.ExampleProject</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<repositories>
<repository>
<id>eclipse-luna</id>
<layout>p2</layout>
<url>http://download.eclipse.org/releases/luna</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>0.22.0</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>0.22.0</version>
<configuration>
<environments>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</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>
</plugins>
</build>

Missing artifacts on Maven Central Repository

Maven central repository does not have jars and artifacts of Eclipse Juno 4.2 release.
Where can i find all these jars and artifacts(along with pom.xml-including transitive dependencies).It will be helpful for us to resolve all maven dependencies as we are planning to migrate eclipse plugins from 3.2 to 4.2.
Before posting a new question, take a look to the old ones.
I think this thread will reply to your : Maven with Eclipse Juno
We faced a similar Problem. Perhaps you should consider using Tycho to build Eclipse Plugins with Maven. It supports using eclipse update sites as dependency source. This way you do not need to resolve eclipse dependencies from a Maven repository.
Tycho takes the Manifest file as dependency definition. However it is still possible to include maven dependencies. The concrete plugin project has to have the packaging
<packaging>eclipse-plugin</packaging>
If your target platform definition does not contain the needed update sites that contain your dependencies add this to your pom:
<repositories>
<repository>
<id>indigo</id>
<!-- Or juno update site in your case -->
<url>http://download.eclipse.org/releases/indigo/</url>
<layout>p2</layout>
</repository>
</repositories>
Additionally you have to configure the build as following:
<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>
<target>
<artifact>
<!-- coordinates of your target platform definition -->
</artifact>
</target>
<!-- This allows you to additionally consider pom dependencies -->
<pomDependencies>consider</pomDependencies>
<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>
</configuration>
</plugin>
</plugins>