Skip to main content

Find Maven dependency

org.openrewrite.maven.search.FindDependency

Finds first-order dependency uses, i.e. dependencies that are defined directly in a project. Each match is also recorded as a row in the DependenciesDeclared data table.

Recipe source

GitHub: FindDependency.java, Issue Tracker, Maven Central

This recipe is available under the Apache License Version 2.0.

Options

TypeNameDescriptionExample
StringgroupIdThe first part of a dependency coordinate com.google.guava:guava:VERSION. Supports glob.com.google.guava
StringartifactIdThe second part of a dependency coordinate com.google.guava:guava:VERSION. Supports glob.guava
StringversionOptional. An exact version number or node-style semver selector used to select the version number.3.0.0
StringversionPatternOptional. Allows version selection to be extended beyond the original Node Semver semantics. So for example,Setting 'version' to "25-29" can be paired with a metadata pattern of "-jre" to select Guava 29.0-jre-jre

Used by

This recipe is used as part of the following composite recipes:

Example

Parameters
ParameterValue
groupIdjakarta.activation
artifactIdjakarta.activation-api
versionnull
versionPatternnull
Before
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</project>
After
pom.xml
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0.0</version>
<dependencies>
<!--~~>--><dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>2.1.2</version>
</dependency>
</dependencies>
</project>

Usage

This recipe has required configuration parameters and can only be run by users of Moderne. To run this recipe, you will need to provide the Moderne CLI run command with the required options. Or, if you'd like to create a declarative recipe, please see the below example of a rewrite.yml file:

rewrite.yml
---
type: specs.openrewrite.org/v1beta/recipe
name: com.yourorg.FindDependencyExample
displayName: Find Maven dependency example
recipeList:
- org.openrewrite.maven.search.FindDependency:
groupId: com.google.guava
artifactId: guava
version: 3.0.0
versionPattern: '-jre'

You will need to have configured the Moderne CLI on your machine before you can run the following command.

shell
mod run . --recipe FindDependency --recipe-option "groupId=com.google.guava" --recipe-option "artifactId=guava" --recipe-option "version=3.0.0" --recipe-option "versionPattern='-jre'"

If the recipe is not available locally, then you can install it using:

mod config recipes jar install org.openrewrite:rewrite-maven:8.84.0

See how this recipe works across multiple open-source repositories

Run this recipe on OSS repos at scale with the Moderne SaaS.

The community edition of the Moderne platform enables you to easily run recipes across thousands of open-source repositories.

Please contact Moderne for more information about safely running the recipes on your own codebase in a private SaaS.

Data Tables

Dependencies declared

org.openrewrite.maven.table.DependenciesDeclared

Direct (first-order) dependencies declared by the project.

Column NameDescription
Project nameThe name of the project that contains the dependency.
Source setThe source set that contains the dependency.
GroupThe first part of a dependency coordinate com.google.guava:guava:VERSION.
ArtifactThe second part of a dependency coordinate com.google.guava:guava:VERSION.
VersionThe resolved version.
Dated snapshot versionThe resolved dated snapshot version or null if this dependency is not a snapshot.
ScopeMaven scope (e.g. compile, test) or Gradle configuration name (e.g. implementation, testImplementation). For Maven, defaults to compile when no scope is declared.