Skip to content

Commit

Permalink
Use non deprecated constructor (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan Viladrosa authored Jul 26, 2023
1 parent ca0bbd2 commit fb1f022
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class ChangeDependency extends Recipe {
@Nullable
private final String versionPattern;

// Maven only parameters
@Option(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`.",
required = false)
Expand Down Expand Up @@ -102,7 +101,7 @@ public List<Recipe> getRecipeList() {
!Objects.equals(changeGradleDependency.getNewVersion(), newVersion) ||
!Objects.equals(changeGradleDependency.getVersionPattern(), versionPattern)
) {
changeGradleDependency = new org.openrewrite.gradle.ChangeDependency(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern);
changeGradleDependency = new org.openrewrite.gradle.ChangeDependency(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern, overrideManagedVersion);
changeMavenDependency = new org.openrewrite.maven.ChangeDependencyGroupIdAndArtifactId(oldGroupId, oldArtifactId, newGroupId, newArtifactId, newVersion, versionPattern, overrideManagedVersion);
}
return Arrays.asList(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void changeMavenDependency() {
}

@Test
void doNotPinWhenNotVersioned() {
void doNotPinWhenNotVersionedGradle() {
rewriteRun(
spec -> spec
.beforeRecipe(withToolingApi())
Expand Down Expand Up @@ -146,4 +146,44 @@ void doNotPinWhenNotVersioned() {
""")
);
}

@Test
void pinWhenOverrideManagedVersionGradle() {
rewriteRun(
spec -> spec
.beforeRecipe(withToolingApi())
.recipe(new ChangeDependency("mysql", "mysql-connector-java", "com.mysql", "mysql-connector-j", "8.0.x", null, true)),
buildGradle(
"""
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
runtimeOnly 'mysql:mysql-connector-java'
}
""",
"""
plugins {
id 'java'
id 'org.springframework.boot' version '2.6.1'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
runtimeOnly 'com.mysql:mysql-connector-j:8.0.33'
}
""")
);
}
}

0 comments on commit fb1f022

Please sign in to comment.