← All recipes
Moderne licensed

Remove unused dependencies

Recipe IDorg.openrewrite.java.dependencies.RemoveUnusedDependencies
Artifactorg.openrewrite.recipe:rewrite-java-security

Scans through source code collecting references to types and methods, removing any dependencies that are not used from Maven or Gradle build files. This is best effort and not guaranteed to work well in all cases; false positives are still possible. This recipe takes reflective access into account: - When reflective access to a class is made unambiguously via a string literal, such as: Class.forName("java.util.List") that is counted correctly. - When reflective access to a class is made ambiguously via anything other than a string literal no dependencies will be removed. This recipe takes transitive dependencies into account: - When a direct dependency is not used but a transitive dependency it brings in _is_ in use the direct dependency is not removed.

Single recipeProprietary

Usage

This recipe has no required configuration options. You’ll need the Moderne CLI configured before running the command below.

mod run . --recipe org.openrewrite.java.dependencies.RemoveUnusedDependencies

If the recipe isn’t available locally, install it with:

mod config recipes jar install org.openrewrite.recipe:rewrite-java-security:3.36.0

Options

NameTypeDescription
ignoredDependenciesListA list of groupId:artifactId glob patterns for dependencies that should never be removed, even if they appear unused. For example, com.google.*:* would ignore all Google dependencies, and *:lombok would ignore Lombok regardless of group ID.
e.g. org.projectlombok:lombok,com.google.*:*

Data tables

Structured output this recipe can produce.

  • Dependency usage evidenceEvidence showing that a dependency is in use in the project.org.openrewrite.java.dependencies.table.DependencyUsageEvidence
  • Source files that had resultsSource files that were modified by the recipe run.org.openrewrite.table.SourcesFileResults
  • Source files that had search resultsSearch results that were found during the recipe run.org.openrewrite.table.SearchResults
  • Source files that errored on a recipeThe details of all errors produced by a recipe run.org.openrewrite.table.SourcesFileErrors
  • Recipe performanceStatistics used in analyzing the performance of recipes.org.openrewrite.table.RecipeRunStats