openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.29k stars 339 forks source link

Illegal state while comparing versions with latest.release #4684

Open asibross opened 1 week ago

asibross commented 1 week ago

This exception was thrown:

Caused by: java.lang.RuntimeException: Error while visiting build.gradle: java.lang.IllegalStateException: Illegal state while comparing versions : [latest.0.0.0.0.0.0] and [3.0.1]. Metadata = [3.0.1]
  org.openrewrite.semver.LatestRelease.compare(LatestRelease.java:164)
  org.openrewrite.semver.VersionComparator.upgrade(VersionComparator.java:45)
  org.openrewrite.gradle.DependencyVersionSelector.select(DependencyVersionSelector.java:142)
  org.openrewrite.gradle.DependencyVersionSelector.select(DependencyVersionSelector.java:83)
  org.openrewrite.gradle.UpgradeDependencyVersion$1.visitMethodInvocation(UpgradeDependencyVersion.java:227)
  org.openrewrite.gradle.UpgradeDependencyVersion$1.visitMethodInvocation(UpgradeDependencyVersion.java:148)

When using a gradle dependency with map notation and latest.release version. For example:

implementation group: 'com.jayway.jsonpath', name: 'json-path', version: 'latest.release'

When using String notation things work as expected:

implementation 'com.jayway.jsonpath:json-path:latest.release'

What version of OpenRewrite are you using?

rewrite-core version: 8.40.2

How are you running OpenRewrite?

I am using the Gradle init script.

timtebeek commented 1 week ago

Thanks for the report @asibross ! Indeed seems like we're misinterpreting the version for that particular notation. Would you want to help resolve the issue by opening a draft PR that adds a unit test first? UpgradeDependencyVersionTest.java has a few examples already that should be easy to copy and adjust to match your case.

shanman190 commented 1 week ago

Just to tack on here, but I'm positive that this same thing would happen for latest.integration as well. So the fix is probably just covering those two SemVer types as no upgrade available edge cases.