Igor P
Igor P

Reputation: 85

Generate metatype descriptions with maven-scr-plugin and OSGI R6 annotations

I am using maven-scr-plugin to generate component and metatype descriptions. I am migrating from org.apache.felix.scr annotations to org.osgi.service.component annotations.

Carsten Ziegeler has written an excellent blog on how to do this migration here. However, that does not explain on how to have the metatype descriptions directly generated from the component annotations. Instead, I would have to make a separate configuration @interface for every component, and rewrite all component activators (at least, to make use of the added value of those extra @interface classes).

I can still use the maven-scr-plugin to process the osgi annotations by adding a dependency on org.apache.felix.scr.ds-annotations. However, maven-scr-plugin only outputs metatype information if that is explicitly switched on. With the felix annotations, a dedicated parameter metatype=true in the @Component annotation is available to enable metatype generation. However, such a parameter is not available in the OSGi version of the @Component annotation.

Is there a way to either force maven-scr-plugin to generate the metatype descriptions, or can I make maven-bundle-plugin (or bndtools) to generate the metatype data based on the osgi @Component annotation, instead of having to define a dedicated configuration class for every component?

Upvotes: 0

Views: 821

Answers (2)

Peter Kriens
Peter Kriens

Reputation: 15372

Metatype is generated when you use the @Designate annotation. (At least in the bnd implementation.)

 @Designate( ocd=Config.class, factory=true )
 @Component
 public class SomeComponent {
    @ObjectClassDefinition
    @interface Config {
       int port();
    }
    @Activate
    void activate( Config config) { }
 }

Upvotes: 1

Christian Schneider
Christian Schneider

Reputation: 19606

As far as I know you need a separate configuration @interface for each component. It is also not possible to generate the meta type from the @Component annotations as they do not describe configurations.

Upvotes: 0

Related Questions