Add Gradle dependency

Apache 2.0

Add a gradle dependency to a build.gradle file in the correct configuration based on where it is used. If the dependency is already declared at a lower version, that declaration is upgraded instead.

org.openrewrite.gradle.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'

Optional

An exact version number or node-style semver selector used to select the version number. You can also use latest.release for the latest available version and latest.patch if the current version is a valid semantic version. For more details, you can look at the documentation page of version selectors.

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 configuration 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 new as of yet unused dependency.

Used to determine if the dependency will be added and in which scope it should be placed.

A classifier to add. Commonly used to select variants of a library.

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

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.gradle.AddDependency \ -P groupId=com.google.guava \ -P artifactId=guava

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