openrewrite / openrewrite/rewrite-spring

Flyway 10 migration adds maven dependencies with incorrect scope

Open
#1,052 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Java
Stars
403
Forks
149
Avg merge
2h 33m
Merged PRs (30d)
10

Description

What version of OpenRewrite are you using?

I am using

  • rewrite-spring v6.33.0 (latest)

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

What is the smallest, simplest way to reproduce the problem?

When flyway-core is defined with test scope, flyway-database-postgresql (and similar dependencies for oracle, sqlserver, etc.) should be added with same test scope.

Modified example from MigrateToFlyway10Test.java:

              <project>
              	<modelVersion>4.0.0</modelVersion>
              	<parent>
              		<groupId>org.springframework.boot</groupId>
              		<artifactId>spring-boot-starter-parent</artifactId>
              		<version>3.3.12</version>
              		<relativePath/>
              	</parent>
              	<groupId>com.example</groupId>
              	<artifactId>demo</artifactId>
              	<version>0.0.1-SNAPSHOT</version>
              	<dependencies>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-core</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.postgresql</groupId>
              			<artifactId>postgresql</artifactId>
              			<scope>runtime</scope>
              		</dependency>
              	</dependencies>
              </project>

What did you expect to see?

              <project>
              	<modelVersion>4.0.0</modelVersion>
              	<parent>
              		<groupId>org.springframework.boot</groupId>
              		<artifactId>spring-boot-starter-parent</artifactId>
              		<version>3.3.12</version>
              		<relativePath/>
              	</parent>
              	<groupId>com.example</groupId>
              	<artifactId>demo</artifactId>
              	<version>0.0.1-SNAPSHOT</version>
              	<dependencies>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-core</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-database-postgresql</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.postgresql</groupId>
              			<artifactId>postgresql</artifactId>
              			<scope>runtime</scope>
              		</dependency>
              	</dependencies>
              </project>

What did you see instead?

              <project>
              	<modelVersion>4.0.0</modelVersion>
              	<parent>
              		<groupId>org.springframework.boot</groupId>
              		<artifactId>spring-boot-starter-parent</artifactId>
              		<version>3.3.12</version>
              		<relativePath/>
              	</parent>
              	<groupId>com.example</groupId>
              	<artifactId>demo</artifactId>
              	<version>0.0.1-SNAPSHOT</version>
              	<dependencies>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-core</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-database-postgresql</artifactId>
              		</dependency>
              		<dependency>
              			<groupId>org.postgresql</groupId>
              			<artifactId>postgresql</artifactId>
              			<scope>runtime</scope>
              		</dependency>
              	</dependencies>
              </project>

Another variation of the same problem

What's more, if flyway-database-postgresql is already defined with test scope, then after running the migration scope gets deleted.
Example initial state:

              <project>
              	<modelVersion>4.0.0</modelVersion>
              	<parent>
              		<groupId>org.springframework.boot</groupId>
              		<artifactId>spring-boot-starter-parent</artifactId>
              		<version>3.3.12</version>
              		<relativePath/>
              	</parent>
              	<groupId>com.example</groupId>
              	<artifactId>demo</artifactId>
              	<version>0.0.1-SNAPSHOT</version>
              	<dependencies>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-core</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.flywaydb</groupId>
              			<artifactId>flyway-database-postgresql</artifactId>
              			<scope>test</scope>
              		</dependency>
              		<dependency>
              			<groupId>org.postgresql</groupId>
              			<artifactId>postgresql</artifactId>
              			<scope>runtime</scope>
              		</dependency>
              	</dependencies>
              </project>

Expected and actual result would be same as with the first case.

Are you interested in [contributing a fix to OpenRewrite]

I could contribute, if given some hints how to make a fix.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with MigrateToFlyway10Test.java and run the existing migration tests to reproduce both scope cases. Trace the Flyway 10 migration implementation that adds or updates dependencies. Done means added Flyway database dependencies preserve the flyway-core scope, and existing dependency scopes are not removed.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.