Skip to content

Not to exclude a test dependency if the dependency is used in another dependency #185

@suztomo

Description

@suztomo

Suppose we have the following 3 artifacts:

  • Artifact A has compile-scope (default) dependency to Artifact B.
  • Artifact A has test-scope dependency to Artifact C.
  • Artifact B has compile-scope (default) dependency to Artifact C.

Diagram:

tri-dependency

Artifact A's pom.xml is flattened before publishing to Maven Central.

Expected Result

Artifact A's flattened pom.xml does not exclude Artifact C when declaring ArtifactB's dependency. Artifact C may be used only in test in Artifact A, but it's needed by Artifact B.

Actual Result

With current implementation, Artifact A's flattened pom.xml excludes Artifact C from Artifact B's dependency. Artifact A's pom.xml would look like something like this:

  <groupId>g</groupId>
  <artifactId>Artifact A<artifactId>
...
  <dependency>
     <groupId>g</groupId>
     <artifactId>Artifact B</artifactId>
     <exclusions>
...
       <exclusion>
         <groupId>g</groupId>
         <artifactId>Artifact C</artifactId>
       </exclusion>

Version

flatten-maven-plugin version 1.2.5

Plugin Parameters

        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>flatten-maven-plugin</artifactId>
          <version>1.2.5</version>
          <executions>
            <!-- enable flattening -->
            <execution>
              <id>flatten</id>
              <phase>process-resources</phase>
              <goals>
                <goal>flatten</goal>
              </goals>
            </execution>
            <!-- ensure proper cleanup -->
            <execution>
              <id>flatten.clean</id>
              <phase>clean</phase>
              <goals>
                <goal>clean</goal>
              </goals>
            </execution>
          </executions>
          <configuration>
            <flattenMode>oss</flattenMode>
            <flattenDependencyMode>all</flattenDependencyMode>
            <pomElements>
              <build>remove</build>
            </pomElements>
          </configuration>
        </plugin>

from com.google.cloud:google-cloud-shared-config:0.9.4

Real Example

In the example we encountered,

  • Artifact A: com.google.cloud:google-cloud-spanner-jdbc
  • Artifact B: com.google.cloud:google-cloud-spanner
  • Artifact C: com.google.api.grpc:grpc-google-cloud-spanner-admin-database-v1

The published pom.xml of com.google.cloud:google-cloud-spanner-jdbc (link) had the unexpected exclusion element:

   <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-spanner</artifactId>
      <version>2.0.2</version>
      <scope>compile</scope>
      <exclusions>
...
        <exclusion>
          <artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
          <groupId>com.google.api.grpc</groupId>
        </exclusion>

(CC: @stephaniewang526 , thank you for helping me on the troubleshooting last week)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions