I have an OSGi component which looks like this
@Activate
public MyComponent(@Reference OtherServiceA ref1, @Reference OtherServiceB ref2, @Reference OtherServiceC ref3) {
// remainder omitted
}
The @Reference annotation does not appear anywhere else in the source.
I'm using gradle 5.6 with the BND tools to build the jar:
// file: build.gradle
plugins {
id 'biz.aQute.bnd.builder'
}
Running the jar task results in the following error:
> Task :my.pro.ject:jar FAILED
error : In component my.pro.ject.mypackage.MyComponent, @Reference cannot be used for method parameters
FAILURE: Build failed with an exception.
and the corresponding stack trace
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':my.pro.ject:jar'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:166)
[...]
Caused by: org.gradle.api.GradleException: Bundle my.pro.ject-2.0.0-SNAPSHOT.jar has errors
at aQute.bnd.gradle.BundleTaskConvention.failBuild(BundleTaskConvention.groovy:310)
at aQute.bnd.gradle.BundleTaskConvention$_buildBundle_closure6$_closure7.doCall(BundleTaskConvention.groovy:294)
at aQute.bnd.gradle.BundleTaskConvention$_buildBundle_closure6.doCall(BundleTaskConvention.groovy:200)
at org.gradle.util.ClosureBackedAction.execute(ClosureBackedAction.java:71)
[...]
I believe the error message is misleading: The following code works well:
@Activate
public MyComponent(@Reference OtherServiceA ref1, @Reference OtherServiceB ref2) { // just removed ref3
// remainder omitted
}
- I don't get an error when I remove the 3rd referenced service (have only the first two)
- I do get the error when I reference the 3rd component e.g. at first or second option.
- The tasks compileJava work well - apparently no syntax or unresolved import issue
- I ran gradle with
clean--refresh-dependencies, nothing worked - I cleared the ~/.gradle/caches directory (Windows home path), without effect
- This is a "doesn't work on my machine" problem: It runs with "exactly" the same setup (same source, same version of references, same java and gradle version) on other machines.
Further details: - I'm using Java 1.8.151(32-bit)
You do not specify the version for the
biz.aQute.bnd.builderplugin. The latest release is5.0.1which definitely has support for OSGi DS 1.4 annotations which support constructor injection.You also do not mention which version of the OSGi DS annotations you use. You must use version 1.4 to use constructor injection.
As for why it only fails on your machine, I cannot say :-(