Tycho cannot resolve fragment dependency on other fragment
Asked Answered
C

2

5

I want to create an extension for org.eclipse.swt as a fragment. I have created a bundle swt.extension with the following MANIFEST.MF:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Extension
Bundle-SymbolicName: swt.extension
Bundle-Version: 1.0.0.qualifier
Fragment-Host: org.eclipse.swt;bundle-version="3.102.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7

Also, I have created an interface which extends an interface from SWT:

public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {
}

When I build my project with tycho (mvn clean install) the following error occurs:

1. ERROR in C:\<path>\tycho-fragment-to-fragment-dependency\swt.extension\src\org\example\tycho_example\IExtendedStyleTextContent.java (at line 3)

public interface IExtendedStyleTextContent extends org.eclipse.swt.custom.StyledTextContent {

                                                   ^^^^^^^^^^^

org.eclipse cannot be resolved to a type

It seems that tycho resolves only org.eclipse.swt jar. This is a host bundle and it contains no classes. The actual implementation is in org.eclipse.swt.win32.win32.x86_64 fragment bundle. And it looks like this bundle is not on classpath when tycho-compiler-plugin compiles the project.

Is this a bug of Tycho? Are their any workarounds?

I have put all sources on GitHub: https://github.com/orionll/tycho-fragment-to-fragment-dependency

I use maven 3.1.0

Clothbound answered 11/8, 2013 at 11:11 Comment(0)
C
6

So, a workaround for this issue was found in mailing lists: http://dev.eclipse.org/mhonarc/lists/tycho-user/msg03277.html

To solve the issue one should add the following sections to POM and build.properties:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.tycho</groupId>
      <artifactId>target-platform-configuration</artifactId>
      <version>${tycho-version}</version>
      <configuration>
        <dependency-resolution>
          <extraRequirements>
            <requirement>
              <type>eclipse-plugin</type>
              <id>org.eclipse.swt.win32.win32.x86_64</id>
              <versionRange>[3.0.0,4.0.0)</versionRange>
            </requirement>
          </extraRequirements>
        </dependency-resolution>
      </configuration>
    </plugin>
  </plugins>
</build>

build.properties:

extra.. = platform:/fragment/org.eclipse.swt.win32.win32.x86_64

I have also updated the GitHub repository

Clothbound answered 11/8, 2013 at 12:38 Comment(4)
BTW, the fact that you need the extraRequirements is a bug in SWT: bugs.eclipse.org/bugs/show_bug.cgi?id=361901Eleonoreleonora
Please take care to put the dependency-resolution into the pom.xml of the fragment and the extra.. into the build.properties of the plugin that uses the fragment.Antipode
@Eleonoreleonora So, is this bug fixed? How should I update my POM to avoid extraRequirements?Clothbound
Thank you very much! The extra.. build.properties addition solved this issue for me. I spent many hours on this, thanks!Sadie
A
4

This is not so much a bug, but a fundamental issue with the design of PDE/Tycho: the build dependencies are kept as close as possible to the runtime dependencies. In this case you need to add a build dependency that doesn't have a corresponding dependency in the runtime, therefore cannot be declared through the OSGi manifest.

The following mailing list message appears to offer a workaround for exactly this issue: http://dev.eclipse.org/mhonarc/lists/tycho-user/msg03277.html

Aharon answered 11/8, 2013 at 11:38 Comment(1)
Thank you for the link. I will post a separate answer for my question.Clothbound

© 2022 - 2024 — McMap. All rights reserved.