Search code examples
mavenosgiequinoxjava-10maven-scr-plugin

maven-scr-plugin does not generate OSGI-INF folder structure with java 10


Does anybody know whether maven scr plugin is compatible with java 10?

I am trying to build an equinox osgi based software platform with java 10 and i am unable to get the scr plugin to generate the OSGI-INF folder structure (which contains serviceComponents.xml) in target folder. As a results maven bundle plugin complains it cannot find the serviceComponents.xml and the build fails.

Everything works fine if I use an older version of scr plugin (1.7.4) with java 8.

If I try to build it with java 10 following error occurs.

[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.7.4:scr (generate-scr-scrdescriptor) on project carbon-kernel: Execution generate-scr-scrdescriptor of goal org.apache.felix:maven-scr-plugin:1.7.4:scr failed: org.apache.felix.scrplugin.tags.annotation.AnnotationTagProvider is not an ImageIO SPI class

When I upgrade the maven scr plugin version to 1.26.0 (latest) it complains that "No annotation processors found in classpath"

So I added org.apache.felix.scr.annotations as an dependency according to instructions in Apache Felix Maven SCR Plugin Use

Now i am getting the following error:

[ERROR] Manifest org.wso2.carbon:org.wso2.carbon.registry.core:bundle:4.4.34-SNAPSHOT : Input file does not exist: target/scr-plugin-generated/OSGI-INF/serviceComponents.xml

I have tried this even with the latest equinox release (Photon) which does not available in maven central repo.

Any help is much appreciated.


Solution

  • I could get the maven scr plugin to work with java 10 and with felix scr annotations by modifying felix.scr.generator-1.1.4 library which is a dependency of the maven scr plugin version 1.7.4 (which worked fine with java 8 as I mentioned in the question)

    I replaced

    final Iterator<AnnotationTagProvider> serviceIter = ServiceRegistry.lookupProviders(AnnotationTagProvider.class, classLoader);
    

    with

    final Iterator<AnnotationTagProvider> serviceIter = ServiceLoader.load(AnnotationTagProvider.class, classLoader).iterator();
    

    in AnnotationTagProviderManager class of felix.scr.generator-1.1.4

    as suggested in a similar issue.

    And also updated the maven compiler plugin source and target configurations. Now OSGI-INF folder structure is generated with the modified felix scr generator and felix scr plugin

    Here are some facts I have found out - hoping this will help someone,

    In order to automatically generate osgi metadata xmls during the maven build either of following annotation schemas can be used.

    • Felix SCR annotations
    • OSGi declarative services (DS) annotations

    Older versions of maven scr plugin has used felix scr annotations but later on its mentioned on the documentations that it has started to support both felix scr annotations and DS annotations from osgi which is the standard set of annotations for generating osgi meta data xmls. This is done by adding the relevant dependency to pom with the scr plugin. However newer versions of scr plugin do not seem to be supporting felix scr annotations and what I found from the community is that the scr plugin is in maintenance mode and it is better to use maven bundle plugin (without the scr plugin) which only supports osgi ds annotations.

    Since felix scr annotations are used in the software platform I am upgrading I had 2 options to proceed. Either to fix java 10 compatibility issues in the older version (1.7.4) of scr plugin or to convert existing scr annotation usages into osgi ds annotations so that I can avoid using the scr plugin. I decided its better to try and keep the existing annotation schema because changing it affects those who use the platform with their own osgi bundles.