# Require-Capability attribute not consistent

**URL:** <https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113>\
**Category:** GENERAL\
**Created:** [March 19, 2021, 12:25pm UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113 "2021-03-19T12:25:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![markt-asf](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/markt-asf/32/82_2.png) [@markt-asf](https://bnd.discourse.group/u/markt-asf)\
**Post date:** [March 19, 2021, 12:25pm UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/1 "2021-03-19T12:25:01Z")

</div>

I am working on reproducible builds for Apache Tomcat. Tomcat uses Bnd, via Ant, to generate OSGi and JPMS metadata.

`reproducible` has been set to `true` but in one JAR I am seeing variation in the `Require-Capability` attribute from one build to the next.

The difference appears to be one of ordering. The two variations are:

```auto
Require-Capability: osgi.contract;osgi.contract=JavaServlet;filter:="(
 &(osgi.contract=JavaServlet)(version=5.0.0))",osgi.contract;osgi.cont
 ract=JavaEL;filter:="(&(osgi.contract=JavaEL)(version=4.0.0))",osgi.e
 e;filter:="(&(osgi.ee=JavaSE)(version=1.8))"

```

and

```auto
Require-Capability: osgi.contract;osgi.contract=JavaEL;filter:="(&(osg
 i.contract=JavaEL)(version=4.0.0))",osgi.contract;osgi.contract=JavaS
 ervlet;filter:="(&(osgi.contract=JavaServlet)(version=5.0.0))",osgi.e
 e;filter:="(&(osgi.ee=JavaSE)(version=1.8))"

```

I have been exploring this with a simple test case. I haven’t been able to reproduce it exactly, but I can reproduce it by switching between using `<fileset dir="${basedir}" includes="*.jar" />` and explicit `<apthelement .../>` entries when setting the class path for Bnd. I’ve checked with `<pathconvert ... />` and the resulting classpath is the same in both cases. I’m not exactly sure what is going on but it looks to be related to the order in which the JARs are processed by Bnd.

Is there some other Bnd configuration I should be using to avoid this or is this a bug in Bnd?

Thanks,

Mark

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [March 19, 2021, 12:39pm UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/2 "2021-03-19T12:39:48Z")

</div>

Perhaps Bnd is added the clauses in encounter order which may vary for different file systems.

So we would need to fix Bnd to do some sorting on the clauses .

In the interim, you could attempt to modify your build to make sure the classpath order is consistent. `<fileset dir="${basedir}" includes="*.jar" />` is probably not reliable for this.

---

<div class="post-metadata">

**Author:** ![markt-asf](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/markt-asf/32/82_2.png) [@markt-asf](https://bnd.discourse.group/u/markt-asf)\
**Post date:** [March 19, 2021, 1:58pm UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/3 "2021-03-19T13:58:17Z")

</div>

Thanks. I’ll see what I can do to refactor the Tomcat build to work around this. Do you want me to open an issue for the ordering of the `Require-Capability` clauses?

---

<div class="post-metadata">

**Author:** ![bjhargrave](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/bjhargrave/32/10_2.png) [@bjhargrave](https://bnd.discourse.group/u/bjhargrave)\
**Post date:** [March 19, 2021, 10:30pm UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/4 "2021-03-19T22:30:05Z")

</div>

Yes, please. I suspect we may need to “normalize” the values of `Provide-Capability` also.

---

<div class="post-metadata">

**Author:** ![pkriens](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/pkriens/32/3_2.png) [@pkriens](https://bnd.discourse.group/u/pkriens)\
**Post date:** [March 22, 2021, 9:36am UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/5 "2021-03-22T09:36:34Z")

</div>

I you have a random order in your class path you’re bound to run into other differences. I think in a repeatable build it is crucial that you control the cp ordering.

---

<div class="post-metadata">

**Author:** ![markt-asf](https://yyz2.discourse-cdn.com/free1/user_avatar/bnd.discourse.group/markt-asf/32/82_2.png) [@markt-asf](https://bnd.discourse.group/u/markt-asf)\
**Post date:** [March 22, 2021, 9:50am UTC](https://bnd.discourse.group/t/require-capability-attribute-not-consistent/113/6 "2021-03-22T09:50:27Z")

</div>

There is more going on here than just class path ordering. If I log the class path I can see that the `<fileset ... />` approach and the multiple `<pathelement ... />` approach result in the same class path but different output. If I manipulate the class path ordering by changing the order of the `<pathelement ... />` entries, the output does not change.

I’ll get that issue created.
