Add Maven dependency

Apache 2.0

Add a Maven dependency to a pom.xml file in the correct scope based on where it is used.

org.openrewrite.maven.AddDependency

Required

The first part of a dependency coordinate com.google.guava:guava:VERSION.

The second part of a dependency coordinate com.google.guava:guava:VERSION.

An exact version number or node-style semver selector used to select the version number.

Optional

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

A scope to use when it is not what can be inferred from usage. Most of the time this will be left empty, but is used when adding a runtime, provided, or test dependency.

releasesOnlyBoolean

Whether to exclude snapshots from consideration when using a semver selector

Used to determine if the dependency will be added and in which scope it should be placed. Required for multi-module projects to avoid adding dependencies unnecessarily.

The type of dependency to add. If omitted Maven defaults to assuming the type is "jar".

A Maven classifier to add. Most commonly used to select shaded or test variants of a library

optionalBoolean

Set the value of the <optional> tag. No <optional> tag will be added when this is null.

A pattern, applied to groupIds, used to determine which other dependencies should have aligned version numbers. Accepts '*' as a wildcard character.

acceptTransitiveBoolean

Default false. If enabled, the dependency will not be added if it is already on the classpath as a transitive dependency.

mod run . --recipe=org.openrewrite.maven.AddDependency \ -P groupId=com.google.guava \ -P artifactId=guava \ -P version=29.X

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.