-
-
Notifications
You must be signed in to change notification settings - Fork 305
-
-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bnd-maven-plugin doesn't inherit properties from parent when a bnd file is present #2265
Comments
I am not sure how that would be possible. bnd/maven/bnd-maven-plugin/src/main/java/aQute/bnd/maven/plugin/BndMavenPlugin.java Lines 284 to 289 in d9622f9
The code recurses to the deepest ancestor and then adds the bnd properties from each project on the way back up. The only way a project's parent's bnd properties would be ignored is if a project did not have a parent. |
Run with |
I have worked out what the issue is, and it's not very pleasant... The parent pom file is following maven best practices and declaring the bnd-maven-plugin in the This then becomes a problem because this call doesn't return the configuration in the parent pom (as the plugin isn't part of the build, just the plugin management). bnd/maven/bnd-maven-plugin/src/main/java/aQute/bnd/maven/plugin/BndMavenPlugin.java Line 292 in d9622f9
As a result the configuration is only loaded in the leaf module, at which point the local bnd.bnd file is processed and returned here, ignoring the inline declaration from the parent bnd/maven/bnd-maven-plugin/src/main/java/aQute/bnd/maven/plugin/BndMavenPlugin.java Line 311 in d9622f9
I have put together an integration test case which shows this failing, but I'm not sure how to fix the failure without breaking other things. The commit with the failing test is available at timothyjward@9146d5e if that is helpful |
There were bugs in your test code. I have fixed them and have a change which makes this work. PR shortly. |
I am having second thoughts about my PR. Need to discuss tomorrow with @timothyjward. |
I’m not totally surprised - Maven tests are hard to validate by sight. I’m glad you came up with a fix, I couldn’t see anything obvious that wouldn’t break some of the existing tests! |
Having looked at the commit I think I can see why you are having second thoughts. There is a clear tension between the way that the From my understanding there are effectively three ways to get configuration into an execution of the
From a pure maven perspective plugins are expected to be configured using only option 2, although a variation of option 3 is also used where external files in the current project (i.e. the one being built) are used. When Maven plugins are configured the configurations are inherited through the parent and flattened. This includes configuration at the plugin level, and for the specific execution, with each child's changes are merged on top. This is the way that configuration available to inject into plugins is calculated, and it is applied once to the current project (not separately at each level in the hierarchy. From a bnd perspective this is a bit like every bnd file starting with If we want the
We may be able to tweak around the edges, but we probably need to discuss this more widely, as it would be a moderate change from the current model. |
@njbartlett, @rotty3000 and others may have a view about this |
That's a disappointing loss of functionality, but I agree it is closer to what a Maven user expects since one is not supposed to have any visibility of resources in the parent project (and when the project is referenced on a repository the source resources are not present).
This is not clear to me. Does this mean you can only have one CDATA section anywhere in the parent hierarchy? And the closest one to the leaf project replaces anything in the parents? |
Yes - this is the way that maven configuration overriding works unfortunately. |
Understood, and I think that's what we have to live with. So long as leaf projects are still able to customize (i.e. via merging rather than wholesale replacing) the bnd instructions using a bnd.bnd file. In that case the usual pattern will be that a single parent project contains the default config, and leaf projects that need to extend the defaults provide a bnd.bnd file. Also ideally the cases in which bnd.bnd files are needed at all will be drastically reduced as more useful and standardized Java annotations become available. |
I have updated the PR to allow a leaf project to have a |
@bjhargrave Can you add a milestone for that? I guess this will be released with 4.0? Also it would be great to add a section to the readme (https://github.com/bndtools/bnd/blob/master/maven/bnd-maven-plugin/README.md) covering the inheritance aspects. |
Yes, it would be in 4.0.
Feel like making a PR? :-) |
Not sure I fully understand how inheritance is implemented after this commit. In the documentation we should add a link towards bnd property merging (is there an official documentation around that?) and elaborate which Maven configuration properties are evaluated in which order. Also we should make clear which maven configuration properties are not merged, i.e. are mutually exclusive ( |
Configuration is loaded from parents first. If the parent does not have a configuration, we look for a configuration in pluginManagement. For each project, the bnd file is used, if present, rather than the element. |
This is still not enough. Just think about the case where you have a parent pom like this
There you would still need to evaluate |
I made a proposal for the documentation of the inheritance in #2272. |
Assuming the pluginManagement section applies to the same project that declares it, then Maven will have already included it in the plugins configuration and bnd-maven-plugin does not need to do anything special. Assuming the pluginManagement section does NOT apply to the same project that declares it, then bnd-maven-plugin should not process it. So in either case, we are ok. |
Are you sure about this? If I'm correct then To help me with that, do you provide a SNAPSHOT repository containing |
Yes, the Cloudbees build has a maven shaped repo at https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles/ |
@bjhargrave |
I think the logic for merging plugins with pluginMgmt is in https://github.com/apache/maven/blob/eb6b212b567c287734a2dbbef3c113fe650f1def/maven-model/src/main/java/org/apache/maven/model/merge/ModelMerger.java#L2445. |
@kwin, I did checkout your modified test and the bnd-maven-plugin code is working correctly. Your test change added configuration to the parent pom, so the child pom inherited the I added some debug statements to verify. Here is the execution configuration from the parent project:
You will see that maven has merged the See also the Here is the execution configuration from the child project:
But this
|
Ok, thanks for checking. Then I guess the inheritance works as expected and just needs to be documented properly. |
Actually after looking again at master...kwin:inheritance-fails-when-mixing-pluginMgmt-and-plugins I still think something is broken with the inheritance here. In my modified test I did not touch the bnd instructions at all. I only added a non-leveraged configuration parameter to the parent's plugin config. That should not change the outcome of the generated bundle symbolic name. As I didn't modify the verified BSN I would expect that this would still be the one from before, namely "biz.aQute.bnd-test.test-inheriting-api-bundle", as this would be the outcome with default Maven inheritance means! The properties should always be evaluated in the context of the current project's pom.xml! |
The inheritance is working as expected. Your change added a configuration to the parent project:
Since you added the configuration to the parent project, the value of the Bundle-Symbolic captures the project's artifactId which is not what the test expects. Even though the child project has a pom configuration with a Bundle-SymbolicName value expected by the test:
Since the child project has a bnd.bnd file, that is used rather than the child project's pom configuration. (You can see When the parent project does not have a configuration, the child project's configuration evaluates the pluginManagement contributed configuration in the context of the child project as the parent project's contribution to the configuration and thus has the artifactId expected by the test. The test specifically checks for this behavior. That is, the pluginManagement contribution is done in the context of the project which first defines an execution configuration rather than in the context of the project which defines the pluginManagement contribution. |
If I have a Maven project with the following configuration in a parent pom:
Then that configuration is picked up by child modules, which is good.
If I then add a bnd.bnd file to the child module (so as to add some extra metadata) then this parent configuration is lost. For example if I want to write a persistence bundle using
Then I have to respecify all of the inherited data. This is annoying, and not what I would expect to happen.
The text was updated successfully, but these errors were encountered: