Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 367701

Summary: Optional dependencies in test runtime depends on reactor
Product: z_Archived Reporter: Tobias Oberlies <t-oberlies>
Component: TychoAssignee: Igor Fedorenko <igor>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: igor, pwebster
Version: unspecified   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Example project to reproduce the problem: none

Description Tobias Oberlies CLA 2012-01-02 05:25:39 EST
The fix for bug 351842 introduced the possibility to control if optional dependencies should be on the compile class path or not. Currently, the optionalDepencencies parameter also affects the test runtime: The optional dependencies of referenced other reactor projects are interpreted according to the optionalDependencies compiler setting. This is brittle: When running the test in isolation, the optionalDependencies setting has no effect for the other projects, and hence the test runtime may be different. This is very confusing and may break the partial rebuild use case.

The following implementation details lead to this behaviour:
1) The optionalDependencies parameter changes the "depencency only" metadata generated at the beginning of the build.
2) The test runtime is computed based on the "dependency only" metadata from the reactor. If the test is executed in isolation, there is nothing else in the reactor, i.e. all locally installed bundles have their final metadata, and hence the test runtime may resolve differently.

I see two (reasonable) options to fix this bug:
a) Use the final metadata for the test runtime, and provide a new mechanism for controlling optional dependencies in the test runtime. This is IMHO the preferred solution because it promises the best consistency between reactor and isolated build.
b) Don't apply the dependencyOnly parameter during dependency-only publishing, but only modify the published units, according optionalDependencies parameter, just before dependency resolution (cf. bug 351842 comment 23). In this way, the test runtime could still use the original dependency-only metadata (or metadata that has optionalDependencies manipulated according to other, reactor-independent rules).
Comment 1 Tobias Oberlies CLA 2012-01-02 05:29:40 EST
Created attachment 208909 [details]
Example project to reproduce the problem:
Comment 2 Tobias Oberlies CLA 2012-01-02 05:30:20 EST
(In reply to comment #1)
> Created attachment 208909 [details]
> Example project to reproduce the problem:

Steps to reproduce:
1. Build the whole reactor with mvn clean install
2. Re-build testbundle
    
In the second step, org.eclipse.equinox.frameworkadmin, optionally
required by the reactorbundl is part of the test runtime.
Comment 3 Igor Fedorenko CLA 2012-01-02 07:46:08 EST
As a user, I expect optionalDepencencies to apply to both calculation of compile classpath and test runtime contents by default. The same applies to other aspects of dependency resolution behaviour, like jre execution profile (bug 364095) and additional resolver filters and constrains  (bug 363331).
Comment 4 Igor Fedorenko CLA 2012-01-02 07:56:55 EST
I plan to work on a more elaborate dependency filtering/constraining as part of bug 363331 and will likely cover the problem described in this bug report.
Comment 5 Igor Fedorenko CLA 2012-01-31 21:53:40 EST
This should be fixed now.

I had to make some changes to the provided test project to make it compile and show the problem, see [1] for more details.

The problem is not limited to TestMojo and can appear in any scenario where 'other' reactor projects with optional dependencies use OptionalResolutionAction.REQUIRE (the default). The solution is to calculate dependency-only metadata for 'this' and 'other' reactor projects differently (see [2], which is a variation of option b) proposed in comment #0. In the long term I would like to change target platform to include final metadata of 'other' reactor projects, but this requires changes to maven core and will have to wait.


Also note that fix for bug 363331 changed test runtime calculation to use final metadata of 'other' reactor projects. The test runtime includes optional dependencies of 'this' reactor project by default. I've opened bug 370290 to track this, but do not plan to work on the fix because this can be easily worked around by explicit optionalDependencies=ignore dependency resolution configuration.


[1] http://git.eclipse.org/c/tycho/org.eclipse.tycho.git/commit/?id=0f68973a0bfcff92cac199eb58defdfe1c69cfa1
[2] http://git.eclipse.org/c/tycho/org.eclipse.tycho.git/commit/?id=9d71c422fb004896bbc8b81963393e7ede88b5cc