Closed
Description
When I tried to flatten a pom with dependencies whose is "true" and set flattenDependencyMode == all, I got a flattened pom which parsed the transitive dependencies but with the as "false". I am wondering if it is a potential problem.
The pom we want to flatten contains dependencies:
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<version>3.2.1</version>
<optional>true</optional>
</dependency>
</dependencies>
The core has transitive dependency:
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
What I got in the flattened pom:
<dependencies>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>core</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>dep</artifactId>
<groupId>org.codehaus.mojo.flatten.its</groupId>
</exclusion>
</exclusions>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.mojo.flatten.its</groupId>
<artifactId>dep</artifactId>
<version>3.2.1</version>
<scope>compile</scope>
<optional>false</optional>
</dependency>
</dependencies>
Activity
stephaniewang526 commentedon Jun 17, 2020
This is a valid issue -- as observed in java-bigtable when we try to add flatten plugin with
flattenDependencyMode == all
in the google-cloud-bigtable-emulator module. Full emulator module pom can be found here.flattened pom shows:
As a result,
mvn dependency:list
generates a list of all (both direct and transitive) dependencies as below:The flatten plugin, with
flattenDependencyMode == all
is generating below instead:Notice that "(optional)" is incorrectly set for the transitive dependency (org.hamcrest:hamcrest-core:jar:1.3).
This should be addressed before we can implement flatten plugin in GCP cloud client modules that contain
<optional>true</optional>
dependencies.@saturnism @olamy FYI
saturnism commentedon Jun 17, 2020
it looks like the issue is similar to
<scope>provided</scope>
is being carried through as well, e.g.,consumer -> lib A -> lib B -> lib C (optional)
before flattening, from the perspective of
lib A
, it'slib A -> lib B
and the optional doesn't show up as a transitive.after flattening, it becomes
lib A -> lib B and lib C (optional)
, becauselib C
has been pulled up as a direct, but retain the optional/provided scopes.from the
consumer
perspective of either modes, it'sconsumer -> lib A -> lib B
, and consumer will drop optional/provided dep from transitive deps.but these extra information is unnecessary can prob be removed in the final flattened pom.
saturnism commentedon Jun 17, 2020
@stephaniewang526 pointed out the bigger issue I misread from the initial description:
consumer -> lib A -> lib B (optional) -> lib C
but from perspective of
lib A
, it'slib A -> lib B (optional) and lib C
. solib C
should also be removed from the transitive deps rather than being pulled up.from
consumer
's perspective:consumer -> lib A -> lib C
, which is incorrect.yangnuoyu commentedon Jun 30, 2020
First, we need to make sure that we use dependency-plugin:3.1.2 to generate the dependency list, otherwise there will not show "(optional)" for optional dependencies in the pom.
Second, for lib A -> lib B (optional) -> lib C, if checking the dependency:tree or dependency:list of A, we can find out that lib C will be still in the class path of A but set as "optional", i.e. lib A -> lib B (optional) -> lib C(optional). So I think we need to keep the lib C in the flattened A, i.e. lib A (flattened) -> lib B (optional) and lib C (optional).
fixes mojohaus#160: when the direct dependency is optional, flattened…
stephaniewang526 commentedon Jun 30, 2020
Looks like using the correct version of maven-dependency-plugin (3.1.2) is key to showing
(optional)
in dependency tree. We could add a section in the flattened pom by configuring to ensure that we have this correctly managed from java-shared-config (like in the original pom). @saturnism any concerns?fixes #160: when the direct dependency is optional, flattened its tra…