Skip to content

Commit d4ed2bd

Browse files
committed
Support import into Eclipse 2022-06
Fix a few issues preventing clean project import into Eclipse 2022-06: - `buildSrc` need to limit module imports to prevent clashes with those in the gradle API jar. - The CLI app needs some classpath changes in order to allow compileOnly project dependencies to resolve. - `AbstractJpaAutoConfigurationTests` needs some minor refactoring in order for generic captures to work with the Eclipse compiler.
1 parent 5470a6b commit d4ed2bd

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

buildSrc/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id "java-gradle-plugin"
33
id "io.spring.javaformat" version "${javaFormatVersion}"
44
id "checkstyle"
5+
id "eclipse"
56
}
67

78
repositories {
@@ -110,3 +111,10 @@ gradlePlugin {
110111
test {
111112
useJUnitPlatform()
112113
}
114+
115+
eclipse.classpath.file.whenMerged {
116+
def jreEntry = entries.find { it.path.contains("org.eclipse.jdt.launching.JRE_CONTAINER") }
117+
jreEntry.entryAttributes['module'] = 'true'
118+
jreEntry.entryAttributes['limit-modules'] = 'java.base'
119+
}
120+

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/AbstractJpaAutoConfigurationTests.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.File;
2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import java.util.Set;
2223
import java.util.UUID;
2324

2425
import javax.sql.DataSource;
@@ -236,8 +237,7 @@ void defaultPersistenceManagedTypes() {
236237
this.contextRunner.run((context) -> {
237238
assertThat(context).hasSingleBean(PersistenceManagedTypes.class);
238239
EntityManager entityManager = context.getBean(EntityManagerFactory.class).createEntityManager();
239-
assertThat(entityManager.getMetamodel().getManagedTypes().stream().map(ManagedType::getJavaType)
240-
.toArray(Class<?>[]::new)).contains(City.class).doesNotContain(Country.class);
240+
assertThat(getManagedJavaTypes(entityManager)).contains(City.class).doesNotContain(Country.class);
241241
});
242242
}
243243

@@ -248,8 +248,7 @@ void customPersistenceManagedTypes() {
248248
.run((context) -> {
249249
assertThat(context).hasSingleBean(PersistenceManagedTypes.class);
250250
EntityManager entityManager = context.getBean(EntityManagerFactory.class).createEntityManager();
251-
assertThat(entityManager.getMetamodel().getManagedTypes().stream().map(ManagedType::getJavaType)
252-
.toArray(Class<?>[]::new)).contains(Country.class).doesNotContain(City.class);
251+
assertThat(getManagedJavaTypes(entityManager)).contains(Country.class).doesNotContain(City.class);
253252
});
254253
}
255254

@@ -277,6 +276,11 @@ void customPersistenceUnitPostProcessors() {
277276
});
278277
}
279278

279+
private Class<?>[] getManagedJavaTypes(EntityManager entityManager) {
280+
Set<ManagedType<?>> managedTypes = entityManager.getMetamodel().getManagedTypes();
281+
return managedTypes.stream().map(ManagedType::getJavaType).toArray(Class<?>[]::new);
282+
}
283+
280284
@Configuration(proxyBeanMethods = false)
281285
static class TestTwoDataSourcesConfiguration {
282286

spring-boot-project/spring-boot-cli/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
plugins {
22
id "java"
3+
id "eclipse"
34
id "org.springframework.boot.deployed"
45
id "org.springframework.boot.conventions"
56
id "org.springframework.boot.integration-test"
@@ -11,10 +12,12 @@ configurations {
1112
dependenciesBom
1213
loader
1314
testRepository
15+
compileOnlyProject
16+
compileClasspath.extendsFrom(compileOnlyProject)
1417
}
1518

1619
dependencies {
17-
compileOnly(project(":spring-boot-project:spring-boot"))
20+
compileOnlyProject(project(":spring-boot-project:spring-boot"))
1821
compileOnly("jakarta.servlet:jakarta.servlet-api")
1922
compileOnly("org.apache.groovy:groovy-templates")
2023
compileOnly("org.springframework:spring-web")
@@ -199,3 +202,6 @@ publishing {
199202
}
200203
}
201204

205+
eclipse.classpath { // https://github.com/eclipse/buildship/issues/939
206+
plusConfigurations += [ configurations.compileOnlyProject ]
207+
}

0 commit comments

Comments
 (0)