apache / apache/maven-dependency-plugin
[MDEP-744] copy-dependencies: don't fetch "provided" dependencies if not required
- Dominant language
- Java
- Stars
- 175
- Forks
- 196
- Avg merge
- 19h 30m
- Merged PRs (30d)
- 5
Description
**[Alberto Gallardo](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=argrico@gmail.com)** opened **[MDEP-744](https://issues.apache.org/jira/browse/MDEP-744?redirect=false)** and commented
Copying only `runtime` dependencies (`includeScope=runtime`) of a maven submodule fails due to a `provided` inter-module dependency. This is not expected, as neither the `provided` dependency nor its transitive dependencies should be copied. There is no need to fetch the dependency.
Notice that it is still possible to copy the dependencies if first invoking the `install` goal, but this should not be necessary.
## Project structure
```java
parent
+-- child1
| ^
| |
+-- child2
```
!image-2021-04-22-18-21-39-763.png!
## poms outline
```xml
parent
child1
child2
```
```xml
parent
child1
```
```xml
parent
child2
child1
provided
```
## Steps to reproduce
1. `mvn -pl child2 -am clean dependency:copy-dependencies -DincludeScope=runtime`
## Current
```
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent [pom]
[INFO] child1 [jar]
[INFO] child2 [jar]
[INFO]
[INFO] -------------------------< org.example:parent >-------------------------
[INFO] Building parent 1.0.0-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent ---
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ parent ---
[INFO]
[INFO] -------------------------< org.example:child1 >-------------------------
[INFO] Building child1 1.0-SNAPSHOT [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child1 ---
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ child1 ---
[INFO]
[INFO] -------------------------< org.example:child2 >-------------------------
[INFO] Building child2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent 1.0.0-SNAPSHOT .............................. SUCCESS [ 0.744 s]
[INFO] child1 1.0-SNAPSHOT ................................ SUCCESS [ 0.043 s]
[INFO] child2 1.0-SNAPSHOT ................................ FAILURE [ 0.053 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.178 s
[INFO] Finished at: 2021-04-20T12:47:16+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project child2: Could not resolve dependencies for project org.example:child2:jar:1.0-SNAPSHOT: Failure to find org.example:child1:jar:1.0-SNAPSHOT in https://nexus.tik.uni-stuttgart.de/repository/maven-central was cached in the local repository, resolution will not be reattempted until the update interval of tik-mirror-central has elapsed or updates are forced -> [Help 1]
```
## Expected
`child2` dependencies are copied to `child2/target/dependency`
## Workaround
Forcing the installation of maven artifacts allows the plugin to resolve the depedencies (Note: I have removed many uninteresting lines from the output):
```
mvn -pl child2 -am clean install dependency:copy-dependencies -DincludeScope=runtime
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent [pom]
[INFO] child1 [jar]
[INFO] child2 [jar]
[INFO]
[INFO] -------------------------< org.example:parent >-------------------------
[INFO] Building parent 1.0.0-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ parent ---
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ parent ---
[INFO]
[INFO] -------------------------< org.example:child1 >-------------------------
[INFO] Building child1 1.0-SNAPSHOT [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child1 ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child1 ---
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child1 ---
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child1 ---
[INFO] Building jar: /home/alberto/src-local/mvn-copy-deps/child1/target/child1-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ child1 ---
[INFO] Installing /home/alberto/src-local/mvn-copy-deps/child1/target/child1-1.0-SNAPSHOT.jar to /home/alberto/.m2/repository/org/example/child1/1.0-SNAPSHOT/child1-1.0-SNAPSHOT.jar
[INFO] Installing /home/alberto/src-local/mvn-copy-deps/child1/pom.xml to /home/alberto/.m2/repository/org/example/child1/1.0-SNAPSHOT/child1-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (default-cli) @ child1 ---
[INFO]
[INFO] -------------------------< org.example:child2 >-------------------------
[INFO] Building child2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child2 ---
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ child2 ---
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ child2 ---
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ child2 ---
[INFO] Building jar: /home/alberto/src-local/mvn-copy-deps/child2/target/child2-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ child2 ---
[INFO] Installing /home/alberto/src-local/mvn-copy-deps/child2/target/child2-1.0-SNAPSHOT.jar to /home/alberto/.m2/repository/org/example/child2/1.0-SNAPSHOT/child2-1.0-SNAPSHOT.jar
[INFO] Installing /home/alberto/src-local/mvn-copy-deps/child2/pom.xml to /home/alberto/.m2/repository/org/example/child2/1.0-SNAPSHOT/child2-1.0-SNAPSHOT.pom
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:copy-dependencies (default-cli) @ child2 ---
[INFO] Copying jcaptcha-1.0.jar to /home/alberto/src-local/mvn-copy-deps/child2/target/dependency/jcaptcha-1.0.jar
[INFO] Copying jcaptcha-api-1.0.jar to /home/alberto/src-local/mvn-copy-deps/child2/target/dependency/jcaptcha-api-1.0.jar
[INFO] Copying imaging-01012005.jar to /home/alberto/src-local/mvn-copy-deps/child2/target/dependency/imaging-01012005.jar
[INFO] Copying commons-logging-1.0.4.jar to /home/alberto/src-local/mvn-copy-deps/child2/target/dependency/commons-logging-1.0.4.jar
[INFO] Copying commons-collections-3.2.jar to /home/alberto/src-local/mvn-copy-deps/child2/target/dependency/commons-collections-3.2.jar
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent 1.0.0-SNAPSHOT .............................. SUCCESS [ 0.775 s]
[INFO] child1 1.0-SNAPSHOT ................................ SUCCESS [ 0.939 s]
[INFO] child2 1.0-SNAPSHOT ................................ SUCCESS [ 0.689 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.752 s
[INFO] Finished at: 2021-04-20T12:50:13+02:00
[INFO] ------------------------------------------------------------------------
```
## Additional info
The goal `dependency:collect` works properly because it doesn't download the actual artifacts:
```
mvn -pl child2 -am clean dependency:collect -DincludeScope=runtime
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] parent [pom]
[INFO] child1 [jar]
[INFO] child2 [jar]
[INFO]
[INFO] -------------------------< org.example:parent >-------------------------
[INFO] Building parent 1.0.0-SNAPSHOT [1/3]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ parent ---
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:collect (default-cli) @ parent ---
[INFO]
[INFO] The following files have been resolved:
[INFO] none
[INFO]
[INFO]
[INFO] -------------------------< org.example:child1 >-------------------------
[INFO] Building child1 1.0-SNAPSHOT [2/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child1 ---
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:collect (default-cli) @ child1 ---
[INFO]
[INFO] The following files have been resolved:
[INFO] none
[INFO]
[INFO]
[INFO] -------------------------< org.example:child2 >-------------------------
[INFO] Building child2 1.0-SNAPSHOT [3/3]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ child2 ---
[INFO] Deleting /home/alberto/src-local/mvn-copy-deps/child2/target
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:collect (default-cli) @ child2 ---
[INFO]
[INFO] The following files have been resolved:
[INFO] com.octo.captcha:jcaptcha:jar:1.0:compile
[INFO] com.octo.captcha:jcaptcha-api:jar:1.0:compile
[INFO] com.jhlabs:imaging:jar:01012005:compile
[INFO] commons-logging:commons-logging:jar:1.0.4:compile
[INFO] commons-collections:commons-collections:jar:3.2:compile
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] parent 1.0.0-SNAPSHOT .............................. SUCCESS [ 0.723 s]
[INFO] child1 1.0-SNAPSHOT ................................ SUCCESS [ 0.024 s]
[INFO] child2 1.0-SNAPSHOT ................................ SUCCESS [ 0.032 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.136 s
[INFO] Finished at: 2021-04-20T13:03:52+02:00
[INFO] ------------------------------------------------------------------------
```
## Example code also available on github
https://github.com/gallardo/maven-copy-dependencies-MDEP-744/tree/383ecb46443b08141dff73b3e71e1cf26c37139f
---
**Affects:** 3.1.2
**Attachments:**
- [image-2021-04-20-12-24-46-392.png](https://issues.apache.org/jira/secure/attachment/13024324/image-2021-04-20-12-24-46-392.png) (_16.16 kB_)
- [image-2021-04-22-18-19-17-504.png](https://issues.apache.org/jira/secure/attachment/13024454/image-2021-04-22-18-19-17-504.png) (_8.64 kB_)
- [image-2021-04-22-18-21-39-763.png](https://issues.apache.org/jira/secure/attachment/13024453/image-2021-04-22-18-21-39-763.png) (_9.45 kB_)
- [maven-copy-dependencies-MDEP-744-383ecb46443b08141dff73b3e71e1cf26c37139f.zip](https://issues.apache.org/jira/secure/attachment/13024326/maven-copy-dependencies-MDEP-744-383ecb46443b08141dff73b3e71e1cf26c37139f.zip) (_7.45 kB_)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the dependency:copy-dependencies goal and reproduce the issue using the reported multi-module parent, child1, and child2 structure and the clean dependency:copy-dependencies command. Compare its resolution behavior with dependency:collect, focusing on the provided inter-module dependency and the runtime scope. Done means the command succeeds without install and copies only child2's runtime dependencies to child2/target/dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100