apache / apache/maven-dependency-plugin
[MDEP-790] New Goals: analyze-main and analyze-test
- Dominant language
- Java
- Stars
- 175
- Forks
- 196
- Avg merge
- 19h 30m
- Merged PRs (30d)
- 5
Description
**[Charles Honton](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=charles_honton@intuit.com)** opened **[MDEP-790](https://issues.apache.org/jira/browse/MDEP-790?redirect=false)** and commented
As a user of the dependency plugin, I desire two new goals; analyze-main and analysis-test. Each goal is similar to the analyze-only goal.
The following parameters are supported:
|\|String[]|List of dependencies that will be ignored if they are declared but unused. The filter syntax is:
[groupId]:[artifactId]:[type]:[version]
where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard. *
For example, org.apache. {**}will match all artifacts whose group id starts with org.apache., and :::{**}-SNAPSHOT will match all snapshot artifacts.|
|\|String[]|List of dependencies that will be ignored if they are used but undeclared. The filter syntax is:
[groupId]:[artifactId]:[type]:[version]
where each pattern segment is optional and supports full and partial * wildcards. An empty pattern segment is treated as an implicit wildcard. *
For example, org.apache. {**}will match all artifacts whose group id starts with org.apache., and :::{**}-SNAPSHOT will match all snapshot artifacts.|
|\|boolean|Skip plugin execution completely.
{**}Default value is{**}: false.
{**}User property is{**}: mdep.analyze.skip.|
|\|boolean|Skip analyze-main goal execution.
{**}Default value is{**}: false.
{**}User property is{**}: mdep.analyze.skipMain.|
|\|boolean|Skip analyze-test goal execution.
{**}Default value is{**}: false.
{**}User property is{**}: mdep.analyze.skipTest.|
|\|String[]|Force dependencies as used, to override incomplete result caused by bytecode-level analysis. Dependency format is groupId:artifactId.|
The analyze-main goal will
* Require a Maven project to be executed.
* Require dependency resolution of artifacts in scope: compile.
* Bind by default to the lifecycle phase: process-classes.
The algorithm it implements is as follows:
1. Use byte code inspection on each class in the main artifact to determine the set of classes required to compile the main sources. These classes are the used-classes set. If there is not a main artifact, the used-classes set is empty.
2. Determine in which dependencies each used class is present. Add these dependencies to the used-dependency set.
3. If any used class is present in multiple used-dependency dependencies, add that class and list of dependencies to the multiple-definition map.
4. Add any dependency declared in the _usedDependencies_ parameter to the used-dependency set.
5. The declared-dependency set contains the main-artifact and the compile-scope dependency set from the maven resolver.
6. Add each dependency in the declared-dependency set that is not in the used-dependency set to the declared-but-unused list.
7. Remove any dependency from the declared-but-unused set that matches patterns declared in the _ignoreUnusedDeclaredDependencies_ parameter.
8. The classpath-dependency set contains the main-artifact and the compile-scope, provided-scope, and system-scope dependency sets from the maven resolver.
9. Add each dependency in the used-dependency set that is not in the classpath-dependency set to the used-but-undeclared set
10. Remove any dependency from the used-but-undeclared set that matches patterns declared in the _ignoreUsedUndeclaredDependencies_ parameter.
11. If the multiple-definition map is non-empty, print as warning the class name and artifacts the class is defined in.
12. Print remaining members of declared-but-unused set to the console
13. Print remaining members of used-but-undeclared set to the console
14. If either declared-but-unused set or used-but-undeclared set is not empty, fail the build
The analyze-test goal will
* Require a Maven project to be executed.
* Require dependency resolution of artifacts in scope: test-compile.
* Bind by default to the lifecycle phase: process-test-classes.
The algorithm it implements is the same as analyze-main algorithm with the following modifications:
1. Use the test artifact instead of the main artifact to determine the used-classes set.
5. The declared-dependency set contains the main-artifact, the test-artifact, and the test-scope dependency set from the maven resolver.
2. The classpath-dependency set contains the main-artifact, the test-artifact, and the test-scope, compile-scope, provided-scope, and system-scope dependency sets from the maven resolver
---
**Issue Links:**
- [MDEP-753](https://issues.apache.org/jira/browse/MDEP-753) Non-test dependency reported as Non-test scoped test only dependency
(_**"split from"**_)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by locating the existing analyze-only goal and its Maven dependency-resolution and lifecycle configuration. Compare its behavior with the requested main and test scopes, parameters, and reporting rules. Done means both goals support the stated scopes and phases, produce the requested unused, undeclared, and multiple-definition results, and fail when required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100