This sample project shows how to configure declarative services components using the different methods available:
- embedded in the Gradle build script: See message-producer sample.
- as a separate Groovy script: See message-consumer sample.
- as a separate, standard DS XML file: See components sample.
To apply the Declarative Services Plugin, add this line to your build file:
apply plugin: 'com.athaydes.osgi-ds'
Example:
build.gradle
declarativeServices {
declarations {
component( name: 'classTrieMessageBus' ) {
implementation( 'class': 'com.athaydes.osgi.ds.ClassTrieMessageBus' )
service {
provide( 'interface': 'com.athaydes.osgi.messaging.MessageBus' )
}
}
}
show()
}
Example:
build.gradle
declarativeServices {
declarations = project.file( 'src/main/osgi/declarativeServices.groovy' )
}
declarativeServices.groovy
component( name: 'consumer' ) {
implementation( 'class': 'com.athaydes.osgi.consumer.MessageConsumer' )
reference( name: 'message-bus',
'interface': 'com.athaydes.osgi.messaging.MessageBus',
'cardinality': '1..1',
'policy': 'static',
'bind': 'addMessageBus',
'unbind': 'removeMessageBus' )
}
Example:
build.gradle
declarativeServices {
declarations = project.file( 'src/main/osgi/components.xml' )
}
components.xml
<?xml version="1.0" encoding="UTF-8"?>
<component name='producer' immediate="true">
<implementation class='com.athaydes.osgi.producer.MessageProducer'/>
<reference name="message-bus" interface="com.athaydes.osgi.messaging.MessageBus"
cardinality="0..1" policy="dynamic"
bind="setMessageBus" unbind="removeMessageBus"/>
</component>