Skip to content

ModuleHasDependency problem with Dependency Versions #149

@MBoegers

Description

@MBoegers

What version of OpenRewrite are you using?

Main branch

How are you running OpenRewrite?

via tests

Problem

When we run org.openrewrite.java.dependencies.search.ModuleHasDependency with a version we see wrong behavior in search results leading to not fulfilled preconditions in recipes.

Situation

  • Dependencies 'org.springframework:spring-core:6.1.5' and 'org.springframework:spring-aop:6.2.2' defined, see below

We search for:

  1. 'org.springframework:*:6.1.5' with new ModuleHasDependency("org.springframework", "*", null, 6.1.5, null)
  2. 'org.springframework:*:5.1.5' with new ModuleHasDependency("org.springframework", "*", null, 5.1.5, null)

Expectation

  1. both modules (Gradle and Maven) are marked to have the 'org.springframework:*:6.1.5' Dependency
  2. no module is marked to have the 'org.springframework:*:6.1.5' Dependency

Observation

  1. Maven finds nothing, gradle marks
  2. Maven finds nothing, gradle marks

The problem is that ModuleHasDependency configures DependencyInsight incorrectly (switched scope and version).

Tree t = new DependencyInsight(groupIdPattern, artifactIdPattern, scope, version)

If we correct this we observe a different, wrong behavior. On maven the Recipe behaves correct, Gradle stops finding not exsiting versions but also finds nothing, except if configured using with a caret range.

Test files

pom.xml

<project>
  <groupId>com.example</groupId>
  <artifactId>foo</artifactId>
  <version>1.0.0</version>

  <dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>6.1.5</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aop</artifactId>
      <version>6.2.2</version>
    </dependency>
  </dependencies>
</project>

build.gradle

plugins {
    id 'java-library'
}
repositories {
    mavenCentral()
}
dependencies {
    implementation 'org.springframework:spring-core:6.1.5'
    implementation 'org.springframework:spring-aop:6.2.2'
}

Note

See #150 for reproducing tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions