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

2 Answers 2

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

4
  • BTW, the fact that you need the extraRequirements is a bug in SWT: bugs.eclipse.org/bugs/show_bug.cgi?id=361901
    – oberlies
    Aug 12, 2013 at 7:30
  • 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. Aug 27, 2015 at 14:38
  • @oberlies So, is this bug fixed? How should I update my POM to avoid extraRequirements? Jan 19, 2018 at 6:07
  • 1
    Thank you very much! The extra.. build.properties addition solved this issue for me. I spent many hours on this, thanks!
    – kgibm
    Aug 20, 2020 at 4:48
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

1
  • Thank you for the link. I will post a separate answer for my question. Aug 11, 2013 at 12:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.