Conventions
Use Declarative Service Annotations
UBStore uses OSGi services for implementing, defining and providing functionality. While OSGi provides several ways of handling services (such as registering and listening for services programmatically), we chose to do this by using declarative service annotations.
This implies that
- a declarative services implementation must be running
- the process of generating the bundle jar must also generate the XML service declarations
While applying the UBStore OSGi Gradle Plugin takes care of running a declarative service implementation (it includes Apache Felix SCR), generating the XML service declarations must be enable in the build script with the following snippet (the example project already does this):
bundle {
instruction '-dsannotations', '*'
}
Use SLF4J for logging
Since UBStore essentially is a set of services that can be used, we chose to use SLF4J, the reasoning is pretty similar to an entry in the FAQ:
By only programming against the facade (slf4j-api), the end user (of the UBStore library, i.e. a project that can be deployed) is able to chose his logging framework of preference.
Since UBStore core declares SLF4J as a transitive dependency, by defining UBStore core as a dependency will also pull in SLF4J, meaning you can start logging by simply doing
static final Logger log = LoggerFactory.getLogger(ExampleClass.class)
The actual implementation of a project then probably wants to
declare a runtime dependency for any implementation of SLF4J
so that the deployable directory generated by the osgiDeploy
gradle task includes that implementation and can actually
log something. For example, to include logback (the native
implementation of SLF4J), define the following dependency in
some build.gradle file:
dependencies {
runtime 'ch.qos.logback:logback-classic:+'
}