bndtools / bnd

Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
https://bndtools.org
Other
532 stars 305 forks source link

Resolve operation result in Gradle differs from the result in IDE #4817

Closed amitjoy closed 3 years ago

amitjoy commented 3 years ago

Using the latest version of 6.0.0-SNAPSHOT, the resolve operation result in Gradle differs from the result in IDE. Here is a sample project to reproduce the issue.

How-To:

  1. Inside the project directory, execute ./gradlew :com.qivicon.product.grappa.application:resolve.dev-lcl-gcm --info
  2. The result will differ from the result generated by bndtools in IDE
  3. The expected result is the one generated by bndtools in IDE
amitjoy commented 3 years ago

It seems the properties specified in the sub bnd files of a project are being considered while resolving any bndrun inside it.

amitjoy commented 3 years ago

This [1] is where the results started to differ.

[1] - https://github.com/bndtools/bnd/commit/c5b1a580820c7615bff7bc27bd5a34bd59a73a42

bjhargrave commented 3 years ago

Bndrun files do not include or consider the bnd.bnd file of a project. A bndrun file's parent is the workspace.

The referenced change now infers a -runrequires using the project's built artifacts IF a -runrequires is not specified. I assume your bndrun file specifies a -runrequires instruction and then no inferred -runrequires is added.

bjhargrave commented 3 years ago

In looking at your project, there is no -runrequires instruction specified. Just merged properties. So you can fix by specifying an empty -runrequires in the bndrun file.

-runrequires:

amitjoy commented 3 years ago

Thx @bjhargrave for your quick response. Actually the initial requirements (-runrequires) are inherited from included bnd files and that's why there is no initial requirements (-runrequires) specified in the bndrun file. If I understood you correctly, according to the current changes, if there is no visible initial requirements (-runrequires) specified in the bndrun, the initial requirements will be inferred automatically. I will give it a go and let you know.

bjhargrave commented 3 years ago

Actually the initial requirements (-runrequires) are inherited from included bnd files

As far as I could see there is no -runrequires instruction anywhere. Just -runrequires.dev, etc. merged instructions. So if you specify an empty -runrequires somewhere, the plugin will not infer a -runrequires instruction.

amitjoy commented 3 years ago

de-lcl-gcm.bndrun includes the following:

-include: \
    shared/base.bndrun,\
    \
    shared/dev.bndrun,\
    shared/lcl.bndrun,\
    shared/gcm.bndrun

and shared/dev.bndrun includes shared/frm.bndrun which contains the following initial requirements:

-runrequires.frm: \
    bnd.identity;id='org.apache.felix.converter'

shared/dev.bndrun itself includes the following initial requirements:

-runrequires.dev : bnd.identity;id='biz.aQute.remote.agent'

So, as a result, the following initial requirements are inherited:

-runrequires.dev                    : bnd.identity;id='biz.aQute.remote.agent'
-runrequires.frm: \
    bnd.identity;id='org.apache.felix.converter'

If I resolve the bndrun in Eclipse using Bndtools 6.0.0-SNAPSHOT, the following bundles are picked up by the resolver even though there is no initial requirements specified in the bndrun directly:

Screenshot 2021-09-06 at 18 48 57

bjhargrave commented 3 years ago

So, as a result, the following initial requirements are inherited:

They are not inherited. They are merged properties. https://bnd.bndtools.org/chapters/820-instructions.html#merged-instructions

-runrequires.dev != -runrequires and -runrequires.frm != -runrequires.

The resolve operation will merge them all together, but the plugin code only considers -runrequires because one may want to specific some additional requirements in addition to the inferred requirement from the project's built artifacts. (The gradle plugin tests test this.)

Since you do not want to infer -runrequires from the project's built artifacts, you must specify an empty -runrequires.

Yes, inferring -runrequires and -runee in the maven and gradle plugins is different from the Bndtools UI. So if you don't want to infer in the maven and gradle plugins, it is best to explicitly set -runrequires and -runee in the bndrun.

amitjoy commented 3 years ago

Thx @bjhargrave for clarifying this. Does it also mean that all the -runX instructions should be specified as empty in all the bndruns? In our project, we follow merged properties everywhere so that several bndruns can easily inherit them from a single point of access.

bjhargrave commented 3 years ago

Only -runrequires and -runee are inferred, if not set, by the maven and gradle plugins.

amitjoy commented 3 years ago

Thx a lot, @bjhargrave 👍 I will configure the workspace accordingly and let you know how it looks.

amitjoy commented 3 years ago

Works like a charm 🚀 Thanks @bjhargrave for your continuous support 👍

pkriens commented 3 years ago

But this means the result is different between Eclipse &Gradle in a bnd workspace? That sounds dangerous?