Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
*/
package org.openrewrite.java.dependencies;

import com.fasterxml.jackson.annotation.JsonCreator;
import lombok.AccessLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jspecify.annotations.Nullable;
import org.openrewrite.*;

Expand All @@ -29,7 +29,6 @@

@EqualsAndHashCode(callSuper = false)
@Getter
@RequiredArgsConstructor
public class ChangeDependency extends ScanningRecipe<ChangeDependency.Accumulator> {
// Gradle and Maven shared parameters
@Option(displayName = "Old group ID",
Expand Down Expand Up @@ -83,6 +82,34 @@ public class ChangeDependency extends ScanningRecipe<ChangeDependency.Accumulato
@Nullable
private final Boolean changeManagedDependency;

@Option(displayName = "Change plugin dependencies",
description = "Also change dependencies declared inside Maven plugins. Defaults to true. Has no effect on Gradle dependencies.",
required = false)
@Nullable
private final Boolean changePluginDependencies;

public ChangeDependency(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId,
@Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean overrideManagedVersion,
@Nullable Boolean changeManagedDependency) {
this(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern,
overrideManagedVersion, changeManagedDependency, null);
}

@JsonCreator
public ChangeDependency(String oldGroupId, String oldArtifactId, @Nullable String newGroupId, @Nullable String newArtifactId,
@Nullable String newVersion, @Nullable String versionPattern, @Nullable Boolean overrideManagedVersion,
@Nullable Boolean changeManagedDependency, @Nullable Boolean changePluginDependencies) {
this.oldGroupId = oldGroupId;
this.oldArtifactId = oldArtifactId;
this.newGroupId = newGroupId;
this.newArtifactId = newArtifactId;
this.newVersion = newVersion;
this.versionPattern = versionPattern;
this.overrideManagedVersion = overrideManagedVersion;
this.changeManagedDependency = changeManagedDependency;
this.changePluginDependencies = changePluginDependencies;
}

@Getter
final String displayName = "Change Gradle or Maven dependency";

Expand Down Expand Up @@ -171,7 +198,7 @@ org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId getMavenChangeDepende
if (recipe == null) {
recipe = new org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId(
oldGroupId, oldArtifactId, newGroupId, newArtifactId,
newVersion, versionPattern, overrideManagedVersion, changeManagedDependency);
newVersion, versionPattern, overrideManagedVersion, changeManagedDependency, changePluginDependencies);
mavenDelegate.set(recipe);
}
return recipe;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/rewrite/recipes.csv
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ecosystem,packageName,name,displayName,description,recipeCount,category1,category2,category3,category1Description,category2Description,category3Description,options,dataTables
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.AddDependency,Add Gradle or Maven dependency,"For a Gradle project, add a gradle dependency to a `build.gradle` file in the correct configuration based on where it is used. Or For a maven project, Add a Maven dependency to a `pom.xml` file in the correct scope based on where it is used.",1,,Dependencies,Java,,,Basic building blocks for transforming Java code.,"[{""name"":""groupId"",""type"":""String"",""displayName"":""Group ID"",""description"":""The first part of a dependency coordinate `com.google.guava:guava:VERSION`."",""example"":""com.google.guava"",""required"":true},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact ID"",""description"":""The second part of a dependency coordinate `com.google.guava:guava:VERSION`"",""example"":""guava"",""required"":true},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""An exact version number or node-style semver selector used to select the version number."",""example"":""29.X""},{""name"":""versionPattern"",""type"":""String"",""displayName"":""Version pattern"",""description"":""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"",""example"":""-jre""},{""name"":""onlyIfUsing"",""type"":""String"",""displayName"":""Only if using"",""description"":""Used to determine if the dependency will be added and in which scope it should be placed."",""example"":""org.junit.jupiter.api.*""},{""name"":""classifier"",""type"":""String"",""displayName"":""Classifier"",""description"":""A classifier to add. Commonly used to select variants of a library."",""example"":""test""},{""name"":""familyPattern"",""type"":""String"",""displayName"":""Family pattern"",""description"":""A pattern, applied to groupIds, used to determine which other dependencies should have aligned version numbers. Accepts '*' as a wildcard character."",""example"":""com.fasterxml.jackson*""},{""name"":""extension"",""type"":""String"",""displayName"":""Extension"",""description"":""For Gradle only, The extension of the dependency to add. If omitted Gradle defaults to assuming the type is \""jar\""."",""example"":""jar""},{""name"":""configuration"",""type"":""String"",""displayName"":""Gradle configuration"",""description"":""The Gradle dependency configuration name within which to place the dependency. When omitted the configuration will be determined by the Maven scope parameter. If that parameter is also omitted, configuration will be determined based on where types matching `onlyIfUsing` appear in source code."",""example"":""implementation""},{""name"":""scope"",""type"":""String"",""displayName"":""Maven scope"",""description"":""The Maven scope within which to place the dependency. When omitted scope will be determined based on where types matching `onlyIfUsing` appear in source code."",""example"":""runtime"",""valid"":[""compile"",""provided"",""runtime"",""test""]},{""name"":""releasesOnly"",""type"":""Boolean"",""displayName"":""Releases only"",""description"":""For Maven only, Whether to exclude snapshots from consideration when using a semver selector""},{""name"":""type"",""type"":""String"",""displayName"":""Type"",""description"":""For Maven only, The type of dependency to add. If omitted Maven defaults to assuming the type is \""jar\""."",""example"":""jar"",""valid"":[""jar"",""pom"",""war""]},{""name"":""optional"",""type"":""Boolean"",""displayName"":""Optional"",""description"":""Set the value of the `<optional>` tag. No `<optional>` tag will be added when this is `null`.""},{""name"":""acceptTransitive"",""type"":""Boolean"",""displayName"":""Accept transitive"",""description"":""Default false. If enabled, the dependency will not be added if it is already on the classpath as a transitive dependency."",""example"":""true""}]",
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.ChangeDependency,Change Gradle or Maven dependency,"Change the group ID, artifact ID, and/or the version of a specified Gradle or Maven dependency.",1,,Dependencies,Java,,,Basic building blocks for transforming Java code.,"[{""name"":""oldGroupId"",""type"":""String"",""displayName"":""Old group ID"",""description"":""The old group ID to replace. The group ID is the first part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions."",""example"":""org.openrewrite.recipe"",""required"":true},{""name"":""oldArtifactId"",""type"":""String"",""displayName"":""Old artifact ID"",""description"":""The old artifact ID to replace. The artifact ID is the second part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions."",""example"":""rewrite-testing-frameworks"",""required"":true},{""name"":""newGroupId"",""type"":""String"",""displayName"":""New group ID"",""description"":""The new group ID to use. Defaults to the existing group ID."",""example"":""corp.internal.openrewrite.recipe""},{""name"":""newArtifactId"",""type"":""String"",""displayName"":""New artifact ID"",""description"":""The new artifact ID to use. Defaults to the existing artifact ID."",""example"":""rewrite-testing-frameworks""},{""name"":""newVersion"",""type"":""String"",""displayName"":""New version"",""description"":""An exact version number or node-style semver selector used to select the version number."",""example"":""29.X""},{""name"":""versionPattern"",""type"":""String"",""displayName"":""Version pattern"",""description"":""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"",""example"":""-jre""},{""name"":""overrideManagedVersion"",""type"":""Boolean"",""displayName"":""Override managed version"",""description"":""If the new dependency has a managed version, this flag can be used to explicitly set the version on the dependency. The default for this flag is `false`.""},{""name"":""changeManagedDependency"",""type"":""Boolean"",""displayName"":""Update dependency management"",""description"":""Also update the dependency management section. The default for this flag is `true`.""}]",
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.ChangeDependency,Change Gradle or Maven dependency,"Change the group ID, artifact ID, and/or the version of a specified Gradle or Maven dependency.",1,,Dependencies,Java,,,Basic building blocks for transforming Java code.,"[{""name"":""oldGroupId"",""type"":""String"",""displayName"":""Old group ID"",""description"":""The old group ID to replace. The group ID is the first part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions."",""example"":""org.openrewrite.recipe"",""required"":true},{""name"":""oldArtifactId"",""type"":""String"",""displayName"":""Old artifact ID"",""description"":""The old artifact ID to replace. The artifact ID is the second part of a dependency coordinate 'com.google.guava:guava:VERSION'. Supports glob expressions."",""example"":""rewrite-testing-frameworks"",""required"":true},{""name"":""newGroupId"",""type"":""String"",""displayName"":""New group ID"",""description"":""The new group ID to use. Defaults to the existing group ID."",""example"":""corp.internal.openrewrite.recipe""},{""name"":""newArtifactId"",""type"":""String"",""displayName"":""New artifact ID"",""description"":""The new artifact ID to use. Defaults to the existing artifact ID."",""example"":""rewrite-testing-frameworks""},{""name"":""newVersion"",""type"":""String"",""displayName"":""New version"",""description"":""An exact version number or node-style semver selector used to select the version number."",""example"":""29.X""},{""name"":""versionPattern"",""type"":""String"",""displayName"":""Version pattern"",""description"":""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"",""example"":""-jre""},{""name"":""overrideManagedVersion"",""type"":""Boolean"",""displayName"":""Override managed version"",""description"":""If the new dependency has a managed version, this flag can be used to explicitly set the version on the dependency. The default for this flag is `false`.""},{""name"":""changeManagedDependency"",""type"":""Boolean"",""displayName"":""Update dependency management"",""description"":""Also update the dependency management section. The default for this flag is `true`.""},{""name"":""changePluginDependencies"",""type"":""Boolean"",""displayName"":""Change plugin dependencies"",""description"":""Also change dependencies declared inside Maven plugins. Defaults to true. Has no effect on Gradle dependencies.""}]",
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.DependencyInsight,Dependency insight for Gradle and Maven,"Finds dependencies, including transitive dependencies, in both Gradle and Maven projects. Matches within all Gradle dependency configurations and Maven scopes.",1,,Dependencies,Java,,,Basic building blocks for transforming Java code.,"[{""name"":""groupIdPattern"",""type"":""String"",""displayName"":""Group pattern"",""description"":""Group ID glob pattern used to match dependencies."",""example"":""com.fasterxml.jackson*"",""required"":true},{""name"":""artifactIdPattern"",""type"":""String"",""displayName"":""Artifact pattern"",""description"":""Artifact ID glob pattern used to match dependencies."",""example"":""jackson-*"",""required"":true},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""Match only dependencies with the specified version. Node-style [version selectors](https://docs.openrewrite.org/reference/dependency-version-selectors) may be used. All versions are searched by default."",""example"":""1.x""},{""name"":""scope"",""type"":""String"",""displayName"":""Scope"",""description"":""Match dependencies with the specified Maven scope. All scopes are searched by default."",""example"":""compile"",""valid"":[""compile"",""test"",""runtime"",""provided"",""system""]}]","[{""name"":""org.openrewrite.maven.table.DependenciesInUse"",""displayName"":""Dependencies in use"",""instanceName"":""Dependencies in use"",""description"":""Direct and transitive dependencies in use."",""columns"":[{""name"":""projectName"",""type"":""String"",""displayName"":""Project name"",""description"":""The name of the project that contains the dependency.""},{""name"":""sourceSet"",""type"":""String"",""displayName"":""Source set"",""description"":""The source set that contains the dependency.""},{""name"":""groupId"",""type"":""String"",""displayName"":""Group"",""description"":""The first part of a dependency coordinate `com.google.guava:guava:VERSION`.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact"",""description"":""The second part of a dependency coordinate `com.google.guava:guava:VERSION`.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The resolved version.""},{""name"":""datedSnapshotVersion"",""type"":""String"",""displayName"":""Dated snapshot version"",""description"":""The resolved dated snapshot version or `null` if this dependency is not a snapshot.""},{""name"":""scope"",""type"":""String"",""displayName"":""Scope"",""description"":""Dependency scope. This will be `compile` if the dependency is direct and a scope is not explicitly specified in the POM.""},{""name"":""count"",""type"":""Integer"",""displayName"":""Count"",""description"":""How many times does this dependency appear.""}]}]"
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.DependencyList,Dependency report,Emits a data table detailing all Gradle and Maven dependencies. This recipe makes no changes to any source file.,1,,Dependencies,Java,,,Basic building blocks for transforming Java code.,"[{""name"":""scope"",""type"":""Scope"",""displayName"":""Scope"",""description"":""The scope of the dependencies to include in the report.Defaults to \""Compile\"""",""example"":""Compile"",""valid"":[""Compile"",""Runtime"",""TestRuntime""]},{""name"":""includeTransitive"",""type"":""boolean"",""displayName"":""Include transitive dependencies"",""description"":""Whether or not to include transitive dependencies in the report. Defaults to including only direct dependencies.Defaults to false."",""example"":""true"",""value"":false},{""name"":""validateResolvable"",""type"":""boolean"",""displayName"":""Validate dependencies are resolvable"",""description"":""When enabled the recipe will attempt to download every dependency it encounters, reporting on any failures. This can be useful for identifying dependencies that have become unavailable since an LST was produced.Defaults to false."",""example"":""true"",""valid"":[""true"",""false""],""value"":false}]","[{""name"":""org.openrewrite.java.dependencies.table.DependencyListReport"",""displayName"":""Dependency report"",""instanceName"":""Dependency report"",""description"":""Lists all Gradle and Maven dependencies"",""columns"":[{""name"":""buildTool"",""type"":""String"",""displayName"":""Build tool"",""description"":""The build tool used to manage dependencies (Gradle or Maven).""},{""name"":""path"",""type"":""String"",""displayName"":""Path"",""description"":""Path to the build file declaring the dependency""},{""name"":""groupId"",""type"":""String"",""displayName"":""Group id"",""description"":""The Group ID of the Gradle project or Maven module requesting the dependency.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The Artifact ID of the Gradle project or Maven module requesting the dependency.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of Gradle project or Maven module requesting the dependency.""},{""name"":""dependencyGroupId"",""type"":""String"",""displayName"":""Dependency group id"",""description"":""The Group ID of the dependency.""},{""name"":""dependencyArtifactId"",""type"":""String"",""displayName"":""Dependency artifact id"",""description"":""The Artifact ID of the dependency.""},{""name"":""dependencyVersion"",""type"":""String"",""displayName"":""Dependency version"",""description"":""The version of the dependency.""},{""name"":""direct"",""type"":""boolean"",""displayName"":""Direct Dependency"",""description"":""When `true` the project directly depends on the dependency. When `false` the project depends on the dependency transitively through at least one direct dependency.""},{""name"":""resolutionFailure"",""type"":""String"",""displayName"":""Resolution failure"",""description"":""The reason why the dependency could not be resolved. Blank when resolution was not attempted.""}]},{""name"":""org.openrewrite.maven.table.MavenMetadataFailures"",""displayName"":""Maven metadata failures"",""instanceName"":""Maven metadata failures"",""description"":""Attempts to resolve maven metadata that failed."",""columns"":[{""name"":""group"",""type"":""String"",""displayName"":""Group id"",""description"":""The groupId of the artifact for which the metadata download failed.""},{""name"":""artifactId"",""type"":""String"",""displayName"":""Artifact id"",""description"":""The artifactId of the artifact for which the metadata download failed.""},{""name"":""version"",""type"":""String"",""displayName"":""Version"",""description"":""The version of the artifact for which the metadata download failed.""},{""name"":""mavenRepositoryUri"",""type"":""String"",""displayName"":""Maven repository"",""description"":""The URL of the Maven repository that the metadata download failed on.""},{""name"":""snapshots"",""type"":""String"",""displayName"":""Snapshots"",""description"":""Does the repository support snapshots.""},{""name"":""releases"",""type"":""String"",""displayName"":""Releases"",""description"":""Does the repository support releases.""},{""name"":""failure"",""type"":""String"",""displayName"":""Failure"",""description"":""The reason the metadata download failed.""}]}]"
maven,org.openrewrite.recipe:rewrite-java-dependencies,org.openrewrite.java.dependencies.DependencyResolutionDiagnostic,Dependency resolution diagnostic,"Recipes which manipulate dependencies must be able to successfully access the artifact repositories and resolve dependencies from them. This recipe produces two data tables used to understand the state of dependency resolution.
Expand Down
Loading
Loading