You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some issues with transitive dependency resolution when a dependency uses profiles to select from one or more artifacts:
Dependencies declared in any profile marked as <activeByDefault>true</activeByDefault> are already resolved even if that profile is de-selected in Maven Profiles options
Dependencies from any non-default profile are not transitively resolved even if requesting that profile to be enabled in the Maven Profiles options
My expectation was that enabling/disabling profiles in Maven Profiles configuration of a project would result in identical resolved class path as Maven would see if building the project from command line.
When another project, 'module2', depends on this project, M2Eclipse only ever resolves the transitive dependencies in the "activeByDefault" profile ( 'new'), even when manually selecting the 'old' profile for enablement:
Additionally, if you remove the default profile activation:
Then neither dependency is transitively resolved for 'module2':
In both of these cases, I would have expected 'old-component', which has dependency declared through 'old' profile, should have been on the project class path, since that profile is selected for enablement.
Environment
Operating System: MacOS 15.0
M2E Version: 2.6.1.20240602-2342
Eclipse Version: 4.32.0.v20240601-0610
Java Version: OpenJDK 64-Bit Server VM Temurin-21.0.4+7
The text was updated successfully, but these errors were encountered:
hankolerd
changed the title
Wrong Dependency Tree resolved when an activeByDefault Profile is overridden with another profile
Incorrect Transitive Dependency Resolution when Declared in Profiles
Aug 9, 2024
Actually I need to add some clarification to this issue. By default, Maven does not take into account transitive dependencies coming through profiles in dependencies. i.e. building 'module2' with -Pnew or -Pold does not bring the transitive deps of 'module1'
In the project POM's at my company where I observed this problem, they have declared an additional profile activation through property:
In this case, Maven will activate profiles and honor transitive dependencies in the profiles of dependency POM's if the property is set in the build, i.e. mvn clean install -Pold -Dold or mvn clean install -Pnew -Dnew.
As such, I suspect this is a pretty extreme edge case to swap compile-time dependencies based on build profiles, considering getting even Maven to honor the transitives is kind of relying on a hack and doesn't appear that they really intended to support it by design.
There are some issues with transitive dependency resolution when a dependency uses profiles to select from one or more artifacts:
<activeByDefault>true</activeByDefault>
are already resolved even if that profile is de-selected in Maven Profiles optionsMy expectation was that enabling/disabling profiles in Maven Profiles configuration of a project would result in identical resolved class path as Maven would see if building the project from command line.
The project structure is as follows:
If a project, 'module1', swaps a compile dependency based on enablement of one of two profiles, 'old' or 'new', like so:
When another project, 'module2', depends on this project, M2Eclipse only ever resolves the transitive dependencies in the "activeByDefault" profile ( 'new'), even when manually selecting the 'old' profile for enablement:
Additionally, if you remove the default profile activation:
Then neither dependency is transitively resolved for 'module2':
In both of these cases, I would have expected 'old-component', which has dependency declared through 'old' profile, should have been on the project class path, since that profile is selected for enablement.
Attached is a sample project to reproduce the issue.
M2E-wrong-classpath-profile-override.zip
Environment
Operating System: MacOS 15.0
M2E Version: 2.6.1.20240602-2342
Eclipse Version: 4.32.0.v20240601-0610
Java Version: OpenJDK 64-Bit Server VM Temurin-21.0.4+7
The text was updated successfully, but these errors were encountered: