Package org.openrewrite.gradle.trait
Class GradleDependency
java.lang.Object
org.openrewrite.gradle.trait.GradleDependency
- All Implemented Interfaces:
org.openrewrite.trait.Trait<org.openrewrite.java.tree.J.MethodInvocation>
public class GradleDependency
extends Object
implements org.openrewrite.trait.Trait<org.openrewrite.java.tree.J.MethodInvocation>
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the resolved artifact ID of the dependency after Gradle's dependency resolution.Gets the configuration name for this dependency.@Nullable StringGets the declared artifact ID from the dependency declaration.@Nullable StringGets the declared group ID from the dependency declaration.@Nullable StringGets the declared version from the dependency declaration.org.openrewrite.maven.tree.GroupArtifactVersiongetGav()Gets the resolved group ID of the dependency after Gradle's dependency resolution.@Nullable GradleDependencyGets the inner dependency if this dependency uses platform() or enforcedPlatform().org.openrewrite.maven.tree.ResolvedGroupArtifactVersionGets the resolved version of the dependency@Nullable StringGets the version variable name if the dependency's version is specified via a variable reference rather than a literal value.static booleanisDependencyDeclaration(org.openrewrite.Cursor cursor) booleanChecks if this dependency declaration uses platform() or enforcedPlatform().booleanmatches(org.openrewrite.semver.DependencyMatcher matcher) Checks if this dependency matches the given DependencyMatcher.Removes the version from a dependency declaration.withDeclaredArtifactId(String newArtifactId) Updates the declared artifact ID of a dependency.withDeclaredGroupId(String newGroupId) Updates the declared group ID of a dependency.withDeclaredVersion(@Nullable String newVersion) Updates the declared version of a dependency.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.openrewrite.trait.Trait
getCursor, getTree
-
Constructor Details
-
GradleDependency
public GradleDependency()
-
-
Method Details
-
isDependencyDeclaration
public static boolean isDependencyDeclaration(org.openrewrite.Cursor cursor) -
getGroupId
Gets the resolved group ID of the dependency after Gradle's dependency resolution.- Returns:
- The resolved group ID (e.g., "com.google.guava" from "com.google.guava:guava:VERSION")
-
getArtifactId
Gets the resolved artifact ID of the dependency after Gradle's dependency resolution.- Returns:
- The resolved artifact ID (e.g., "guava" from "com.google.guava:guava:VERSION")
-
getVersion
Gets the resolved version of the dependency- Returns:
- the resolved version of the dependency, after any variable substitutions have taken place
-
getGav
public org.openrewrite.maven.tree.GroupArtifactVersion getGav() -
getResolvedGav
public org.openrewrite.maven.tree.ResolvedGroupArtifactVersion getResolvedGav() -
getConfigurationName
Gets the configuration name for this dependency. For example, "implementation", "testImplementation", "api", etc. For platform dependencies wrapped in platform() or enforcedPlatform(), returns the configuration name of the outer method invocation.- Returns:
- The configuration name
-
getDeclaredGroupId
Gets the declared group ID from the dependency declaration. This may be a literal value or a variable name/expression. For platform dependencies, automatically looks at the inner dependency.- Returns:
- The declared group ID string, or null if it cannot be determined
-
getDeclaredArtifactId
Gets the declared artifact ID from the dependency declaration. This may be a literal value or a variable name/expression. For platform dependencies, automatically looks at the inner dependency.- Returns:
- The declared artifact ID string, or null if it cannot be determined
-
getDeclaredVersion
Gets the declared version from the dependency declaration. This may be a literal value or a variable name/expression. For platform dependencies, automatically looks at the inner dependency.- Returns:
- The declared version string (literal or variable name), or null if it cannot be determined
-
isPlatform
public boolean isPlatform()Checks if this dependency declaration uses platform() or enforcedPlatform().- Returns:
- true if the dependency is wrapped in platform() or enforcedPlatform()
-
getPlatformDependency
Gets the inner dependency if this dependency uses platform() or enforcedPlatform(). For example, forimplementation platform("com.example:bom:1.0"), this returns the GradleDependency representingplatform("com.example:bom:1.0").- Returns:
- The inner GradleDependency if this is a platform dependency, or null otherwise
-
getVersionVariable
Gets the version variable name if the dependency's version is specified via a variable reference rather than a literal value. Handles various dependency notation formats. If this dependency uses platform() or enforcedPlatform(), this method automatically looks at the inner dependency declaration.- Returns:
- The variable name used for the version, or null if the version is a literal or cannot be determined
-
matches
public boolean matches(org.openrewrite.semver.DependencyMatcher matcher) Checks if this dependency matches the given DependencyMatcher. This is a convenience method that extracts the declared group and artifact IDs and passes them to the matcher.- Parameters:
matcher- The DependencyMatcher to check against- Returns:
- true if this dependency matches the matcher's patterns
-
removeVersion
Removes the version from a dependency declaration. This method handles various dependency notation formats including string literals, map literals, and map entries. If this dependency uses platform() or enforcedPlatform(), this method automatically operates on the inner dependency declaration.- Returns:
- A new GradleDependency with the version removed from the cursor's method invocation, or the original GradleDependency if the version cannot be removed
-
withDeclaredGroupId
Updates the declared group ID of a dependency. This method handles various dependency notation formats including string literals, GStrings, map entries, map literals, assignments, and Kotlin string templates. If this dependency uses platform() or enforcedPlatform(), this method automatically operates on the inner dependency declaration.- Parameters:
newGroupId- The new group ID to set- Returns:
- A new GradleDependency with the updated group ID, or the original if no change was made
-
withDeclaredArtifactId
Updates the declared artifact ID of a dependency. This method handles various dependency notation formats including string literals, GStrings, map entries, map literals, assignments, and Kotlin string templates. If this dependency uses platform() or enforcedPlatform(), this method automatically operates on the inner dependency declaration.- Parameters:
newArtifactId- The new artifact ID to set- Returns:
- A new GradleDependency with the updated artifact ID, or the original if no change was made
-
withDeclaredVersion
Updates the declared version of a dependency. This method handles various dependency notation formats including string literals, GStrings, map entries, map literals, assignments, and Kotlin string templates. If this dependency uses platform() or enforcedPlatform(), this method automatically operates on the inner dependency declaration.- Parameters:
newVersion- The new version to set (can be null to remove version)- Returns:
- A new GradleDependency with the updated version, or the original if no change was made
-