diff --git a/biz.aQute.bndlib.tests/test/test/component/DSAnnotationTest.java b/biz.aQute.bndlib.tests/test/test/component/DSAnnotationTest.java index 44b9e95016..4d4cef223f 100644 --- a/biz.aQute.bndlib.tests/test/test/component/DSAnnotationTest.java +++ b/biz.aQute.bndlib.tests/test/test/component/DSAnnotationTest.java @@ -4395,7 +4395,6 @@ public void anyservice() throws Exception { assertOk(b); Attributes a = getAttr(jar); checkProvides(a); - checkRequires(a, ComponentConstants.COMPONENT_SPECIFICATION_VERSION, AnyService.class.getName()); // // Test all the defaults @@ -4444,6 +4443,25 @@ public void anyservice() throws Exception { } } + @Test + public void anyserviceNoServiceRequirement() throws Exception { + try (Builder b = new Builder()) { + b.setProperty(Constants.DSANNOTATIONS, "test.component.DSAnnotationTest$AnyServiceUse"); + b.setProperty("Private-Package", "test.component"); + b.addClasspath(new File("bin_test")); + + Jar jar = b.build(); + assertOk(b); + Attributes a = getAttr(jar); + checkProvides(a); + + jar.getManifest() + .write(System.out); + + assertThat(a.getValue(Constants.REQUIRE_CAPABILITY)).doesNotContain(AnyService.class.getName()); + } + } + @Component public static class AnyServiceUseNoObject { @Activate diff --git a/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java b/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java index e98b3a0a4b..cea8538814 100644 --- a/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java +++ b/biz.aQute.bndlib/src/aQute/bnd/component/DSAnnotations.java @@ -318,6 +318,9 @@ private void addServiceCapability(ComponentDef definition, Set provides, private void addServiceRequirement(ReferenceDef ref, MergedRequirement requires) { String objectClass = ref.service; + if ("org.osgi.service.component.AnyService".equals(objectClass)) { + return; + } ReferenceCardinality cardinality = ref.cardinality; boolean optional = cardinality == ReferenceCardinality.OPTIONAL || cardinality == ReferenceCardinality.MULTIPLE; boolean multiple = cardinality == ReferenceCardinality.MULTIPLE