Open
Description
What version of OpenRewrite are you using?
I am using
- org.openrewrite.maven:rewrite-maven-plugin:6.7.0
- org.openrewrite.recipe:rewrite-spring:6.6.0
- Apache Maven 3.8.7
- org.spockframework:spock-spring:2.4-M6-groovy-4.0
- org.spockframework:spock-core:2.4-M6-groovy-4.0
How are you running OpenRewrite?
I am using the Maven plugin, and my project is a single module project.
run mvn rewrite:run
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.spring-projects.spring-data-jpa</groupId>
<artifactId>test-case-query-sum-enumeration</artifactId>
<version>1.0.0.Final</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<!-- Test works w/ 3.2.12 -->
<version>3.3.11</version>
<!-- Test fails w/ 3.4.5 -->
<!-- <version>3.4.5</version>-->
</parent>
<properties>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.3.232</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-spring</artifactId>
<version>2.4-M6-groovy-4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>2.4-M6-groovy-4.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.14.0</version>
<configuration>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testFailureIgnore>false</testFailureIgnore>
<argLine>-Xmx1024m -Djdk.net.URLClassPath.disableClassPathURLCheck=true @{surefireArgLine}
</argLine>
<useFile>false</useFile>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
<include>**/*Spec.groovy</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<argLine>--illegal-access=permit @{surefireArgLine}</argLine>
<includes>
<include>**/*Test.java</include>
<include>**/*Spec.java</include>
<include>**/*Spec.groovy</include>
</includes>
</configuration>
</plugin>
<!-- command: mvn rewrite:run -->
<plugin>
<groupId>org.openrewrite.maven</groupId>
<artifactId>rewrite-maven-plugin</artifactId>
<version>6.7.0</version>
<configuration>
<activeRecipes>
<recipe>org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3</recipe>
<!-- <recipe>org.openrewrite.java.testing.junit5.JUnit5BestPractices</recipe>-->
</activeRecipes>
</configuration>
<dependencies>
<dependency>
<groupId>org.openrewrite.recipe</groupId>
<artifactId>rewrite-spring</artifactId>
<version>6.6.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
What is the smallest, simplest way to reproduce the problem?
package org.spring.data.jpa.bugs;
import jakarta.persistence.EntityManager;
import org.springframework.stereotype.Component;
@Component
public class OurService {
private final EntityManager entityManager;
public OurService(EntityManager entityManager) {
this.entityManager = entityManager;
}
public void doSomething(String name) {
OurEntity ourEntity = new OurEntity();
ourEntity.setName(name);
entityManager.persist(ourEntity);
}
}
package org.spring.data.jpa.bugs;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.SequenceGenerator;
@Entity
public class OurEntity {
@Id
@SequenceGenerator(name = "ourEntitySeq", sequenceName = "OUR_ENTITY_ID_SEQ", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ourEntitySeq")
private Long id;
@Column(name = "name")
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
package org.spring.data.jpa.bugs
import jakarta.persistence.EntityManager
import spock.lang.Specification
import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.*
class OurServiceSpec extends Specification {
private def entityManagerMock = mock(EntityManager)
private def ourService = new OurService(entityManagerMock)
def "doSomething"() {
given:
def name = "name"
when:
ourService.doSomething(name)
then:
verify(entityManagerMock.persist(any(OurEntity)))
}
}
What did you expect to see?
The build should not remove the (needed) imports of
import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.*
What did you see instead?
The build removes the (needed) imports of
import static org.mockito.ArgumentMatchers.any
import static org.mockito.Mockito.*
What is the full stack trace of any errors you encountered?
Full mvn rewrite:run output:
stsc@linex014:~/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6$ mvn rewrite:run
[INFO] Scanning for projects...
[INFO]
[INFO] --< org.spring-projects.spring-data-jpa:test-case-query-sum-enumeration >--
[INFO] Building test-case-query-sum-enumeration 1.0.0.Final
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> rewrite-maven-plugin:6.7.0:run (default-cli) > process-test-classes @ test-case-query-sum-enumeration >>>
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ test-case-query-sum-enumeration ---
[INFO] skip non existing resourceDirectory /home/stsc/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6/src/main/resources
[INFO] skip non existing resourceDirectory /home/stsc/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.14.0:compile (default-compile) @ test-case-query-sum-enumeration ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:testResources (default-testResources) @ test-case-query-sum-enumeration ---
[INFO] Copying 1 resource from src/test/resources to target/test-classes
[INFO]
[INFO] --- maven-compiler-plugin:3.14.0:testCompile (default-testCompile) @ test-case-query-sum-enumeration ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] <<< rewrite-maven-plugin:6.7.0:run (default-cli) < process-test-classes @ test-case-query-sum-enumeration <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:6.7.0:run (default-cli) @ test-case-query-sum-enumeration ---
[INFO] Using active recipe(s) [org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3, org.openrewrite.java.testing.junit5.JUnit5BestPractices]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [test-case-query-sum-enumeration] Resolving Poms...
[INFO] Project [test-case-query-sum-enumeration] Parsing source files
[INFO] Running recipe(s)...
[WARNING] Changes have been made to orm/hibernate-orm-6/pom.xml by:
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3
[WARNING] org.openrewrite.maven.UpgradeParentVersion: {groupId=org.springframework.boot, artifactId=spring-boot-starter-parent, newVersion=3.3.x}
[WARNING] Changes have been made to orm/hibernate-orm-6/src/test/groovy/org/spring/data/jpa/bugs/OurServiceSpec.groovy by:
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_6
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_5
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_4
[WARNING] org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration
[WARNING] org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING] org.openrewrite.java.testing.junit5.UseMockitoExtension
[WARNING] org.openrewrite.java.testing.mockito.Mockito1to4Migration
[WARNING] org.openrewrite.java.testing.mockito.Mockito1to3Migration
[WARNING] org.openrewrite.java.testing.mockito.CleanupMockitoImports
[WARNING] Please review and commit the results.
[WARNING] Estimate time saved: 10m
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.961 s
[INFO] Finished at: 2025-05-07T09:17:52+02:00
[INFO] ------------------------------------------------------------------------
stsc@linex014:~/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6$ mvn rewrite:run
[INFO] Scanning for projects...
[INFO]
[INFO] --< org.spring-projects.spring-data-jpa:test-case-query-sum-enumeration >--
[INFO] Building test-case-query-sum-enumeration 1.0.0.Final
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> rewrite-maven-plugin:6.7.0:run (default-cli) > process-test-classes @ test-case-query-sum-enumeration >>>
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:resources (default-resources) @ test-case-query-sum-enumeration ---
[INFO] skip non existing resourceDirectory /home/stsc/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6/src/main/resources
[INFO] skip non existing resourceDirectory /home/stsc/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.14.0:compile (default-compile) @ test-case-query-sum-enumeration ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] --- maven-resources-plugin:3.3.1:testResources (default-testResources) @ test-case-query-sum-enumeration ---
[INFO] Copying 1 resource from src/test/resources to target/test-classes
[INFO]
[INFO] --- maven-compiler-plugin:3.14.0:testCompile (default-testCompile) @ test-case-query-sum-enumeration ---
[INFO] Nothing to compile - all classes are up to date.
[INFO]
[INFO] <<< rewrite-maven-plugin:6.7.0:run (default-cli) < process-test-classes @ test-case-query-sum-enumeration <<<
[INFO]
[INFO]
[INFO] --- rewrite-maven-plugin:6.7.0:run (default-cli) @ test-case-query-sum-enumeration ---
[INFO] Using active recipe(s) [org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_3]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] Project [test-case-query-sum-enumeration] Resolving Poms...
[INFO] Project [test-case-query-sum-enumeration] Parsing source files
[INFO] Running recipe(s)...
[WARNING] Changes have been made to orm/hibernate-orm-6/pom.xml by:
[WARNING] org.openrewrite.maven.UpgradeParentVersion: {groupId=org.springframework.boot, artifactId=spring-boot-starter-parent, newVersion=3.3.x}
[WARNING] Changes have been made to orm/hibernate-orm-6/src/test/groovy/org/spring/data/jpa/bugs/OurServiceSpec.groovy by:
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_2
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_1
[WARNING] org.openrewrite.java.spring.boot3.UpgradeSpringBoot_3_0
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_7
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_6
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_5
[WARNING] org.openrewrite.java.spring.boot2.UpgradeSpringBoot_2_4
[WARNING] org.openrewrite.java.spring.boot2.SpringBoot2JUnit4to5Migration
[WARNING] org.openrewrite.java.testing.junit5.JUnit4to5Migration
[WARNING] org.openrewrite.java.testing.junit5.UseMockitoExtension
[WARNING] org.openrewrite.java.testing.mockito.Mockito1to4Migration
[WARNING] org.openrewrite.java.testing.mockito.Mockito1to3Migration
[WARNING] org.openrewrite.java.testing.mockito.CleanupMockitoImports
[WARNING] Please review and commit the results.
[WARNING] Estimate time saved: 10m
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 24.123 s
[INFO] Finished at: 2025-05-07T09:20:03+02:00
[INFO] ------------------------------------------------------------------------
stsc@linex014:~/IdeaProjects/GeoFence/hibernate-test-case-templates/query-sum-enumeration/orm/hibernate-orm-6$
Are you interested in [contributing a fix to OpenRewrite]
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Backlog