You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by "Elliotte Rusty Harold (Jira)" <ji...@apache.org> on 2020/07/17 15:06:00 UTC

[jira] [Closed] (MDEP-687) includeScope=runtime for copy-dependencies does not include transitive compile-time dependencies

     [ https://issues.apache.org/jira/browse/MDEP-687?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Elliotte Rusty Harold closed MDEP-687.
--------------------------------------

> includeScope=runtime for copy-dependencies does not include transitive compile-time dependencies
> ------------------------------------------------------------------------------------------------
>
>                 Key: MDEP-687
>                 URL: https://issues.apache.org/jira/browse/MDEP-687
>             Project: Maven Dependency Plugin
>          Issue Type: Bug
>            Reporter: Dmitry Andrianov
>            Priority: Major
>
> We using {{copy-dependencies}} from dependency plugin to collect all the libraries needed by the application at runtime into a {{lib/}} directory. We obviously do not want to include any test dependencies so we are setting
> {code:xml}
>  <includeScope>runtime</includeScope>{code}
> It normally works as expected except for one case. Imagine::
> {code:java}
> application
>   |
>   + libOne (test)
>   |
>   + libTwo (compile)
>       |
>       + libOne (compile)
>  {code}
> With this layout our application only needs {{libOne}} during tests but at the same time we depend on {{libTwo}} which in turn depends on {{libOne}}. In the end {{libOne}} is required for the application to function. Unfortunately it gets excluded by {{copy-dependencies}} with {{scope=runtime}}. This is a nasty surprise given the documentation [https://maven.apache.org/plugins/maven-dependency-plugin/copy-dependencies-mojo.html#includeScope] says
> {quote}The scopes being interpreted are the scopes as Maven sees them, not as specified in the pom.
> {quote}
> Surely, Maven should see {{libOne}} as a runtime thing when resolving dependencies...
> Below is a full POM that reproduces the case (with arbitrary libraries though).
>  We have {{logback-access}} as compile dependency and it should bring {{logback-core}} with it but because we also declare {{logback-core}} as a test dependency for the application - it gets demoted to test only and not included into {{lib/}} directory.
> {code:xml}
> <?xml version="1.0" encoding="UTF-8"?>
> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>     <modelVersion>4.0.0</modelVersion>
>     <groupId>test</groupId>
>     <artifactId>pom-test</artifactId>
>     <version>0.1</version>
>     <packaging>jar</packaging>
>     <build>
>         <plugins>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-compiler-plugin</artifactId>
>                 <version>3.1</version>
>             </plugin>
>             <plugin>
>                 <groupId>org.apache.maven.plugins</groupId>
>                 <artifactId>maven-dependency-plugin</artifactId>
>                 <version>3.1.2</version>
>                 <executions>
>                     <execution>
>                         <id>copy-dependencies</id>
>                         <phase>package</phase>
>                         <goals>
>                             <goal>copy-dependencies</goal>
>                         </goals>
>                         <configuration>
>                             <outputDirectory>${project.build.directory}/lib</outputDirectory>
>                             <!-- what we trying to do here is to not include any dependencies that are
>                                  needed for testing ONLY into our "final" lib/ directory -->
>                             <includeScope>runtime</includeScope>
>                         </configuration>
>                     </execution>
>                 </executions>
>             </plugin>
>         </plugins>
>     </build>
>     <dependencies>
>         <dependency>
>             <groupId>ch.qos.logback</groupId>
>             <artifactId>logback-access</artifactId>
>             <version>1.2.2</version>
>         </dependency>
>         <dependency>
>             <groupId>ch.qos.logback</groupId>
>             <artifactId>logback-core</artifactId>
>             <version>1.2.2</version>
>             <!-- logback-access has a 'compile' dependency to logback-core  -->
>             <!-- what we trying to say here is that for our test module, we only need it as 'test' -->
>             <!-- however it should still end as a runtime scope because needed by logback-access! -->
>             <scope>test</scope>
>         </dependency>
>         <dependency>
>             <groupId>org.slf4j</groupId>
>             <artifactId>slf4j-api</artifactId>
>             <version>1.7.25</version>
>             <!-- This one is also a test-time dependency and should not end up in the lib/ because nothing
>                  brings it as compile/runtime -->
>             <scope>test</scope>
>         </dependency>
>     </dependencies>
> </project>{code}
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)