Prior to this commit, the Java 21 and Java 24 multi-release sources in spring-core could not be developed or tested within Eclipse, since an Eclipse project supports only a single Java compliance level. This commit configures Eclipse projects that use the multiReleaseJar plugin with the highest multi-release version as their Java baseline (Java 24 for spring-core) and includes the corresponding multi-release source folders. Types which are overridden by a multi-release source folder are excluded from lower source folders, and higher source folders are placed first so that the debugger's source lookup resolves overriding types. A lower baseline can be configured via the "eclipseJavaBaseline" project property: for example, -PeclipseJavaBaseline=17. See gh-37397
4.6 KiB
Spring Framework - Eclipse Project Import Guide
This document will guide you through the process of importing the Spring Framework
projects into Eclipse IDE or the Spring Tools for Eclipse. It is recommended that you
have a recent version of Eclipse. The build uses JDK 25 (see .sdkmanrc), so as a bare
minimum you will need Eclipse with full Java 25 support.
The following instructions have been tested against Spring Tools for Eclipse 5.4.0 (based on Eclipse IDE 4.41). The instructions should also work with the latest release of the Eclipse IDE for Java Developers; Spring Tools is not required.
Steps
When instructed to execute ./gradlew from the command line, be sure to execute it
within your locally cloned spring-framework working directory.
- Ensure that the Forbidden reference (access rule) in Eclipse is set to
Info(Preferences → Java → Compiler → Errors/Warnings → Deprecated and restricted API → Forbidden reference (access rule)). - Optionally install the Kotlin Plugin for Eclipse if you need to execute Kotlin-based tests or develop Kotlin extensions.
- Optionally install the
AspectJ Development Tools
(AJDT) if you need to work with the
spring-aspectsproject. - Optionally install the
TestNG plugin in Eclipse if
you need to execute individual TestNG test classes or tests in the
spring-testmodule.- As an alternative to installing the TestNG plugin, you can execute the
org.springframework.test.context.testng.TestNGTestSuiteclass as a "JUnit 6" test class in Eclipse.
- As an alternative to installing the TestNG plugin, you can execute the
- Compile all main and test classes from the command line first with
./gradlew testClasses. This pre-compilesspring-coreand generates the JAXB types forspring-oxm(see Known Issues below). - To apply Spring Framework specific settings, run
./gradlew cleanEclipse eclipsefrom the command line. - Import all projects into Eclipse (File → Import → General → Existing
Projects into Workspace → Navigate to the locally cloned
spring-frameworkdirectory → Select Finish).- If you have not installed AJDT, exclude the
spring-aspectsproject from the import, if prompted, or close it after the import.
- If you have not installed AJDT, exclude the
- Code away!
Known Issues
spring-coreshould be pre-compiled due to repackaged dependencies.- See
*RepackJartasks in thespring-core.gradlebuild file.
- See
spring-oxmshould be pre-compiled due to JAXB types generated for tests.- Note that executing
./gradlew testClassesas explained in the Steps above will compilespring-coreand generate JAXB types forspring-oxm.
- Note that executing
spring-aspectsdoes not compile due to references to aspect types unknown to Eclipse.- If you installed AJDT into Eclipse it should work.
- Since an Eclipse project supports only a single Java compliance level,
spring-coreis configured with a Java 24 baseline in Eclipse, which includes the Java 21 and Java 24 multi-release sources (src/main/java21,src/main/java24, andsrc/test/java21). Types overridden by those sources are excluded fromsrc/main/java. Eclipse does not report usage of Java features newer than the project-wide Java 17 baseline; however, such usage will be caught by the Gradle build.- To work on the Java 17 or Java 21 variants instead, run
./gradlew eclipse -PeclipseJavaBaseline=17(or21) and refresh the projects in Eclipse (or close and reopen them if the compiler settings are not updated).
- To work on the Java 17 or Java 21 variants instead, run
- While JUnit tests pass from the command line with Gradle, some may fail when run from
the IDE.
- Resolving this is a work in progress.
- If attempting to run all JUnit tests from within the IDE, you may need to set the
following VM option to avoid out of memory errors:
-Xmx2048m - Tests run via Gradle are also configured with the following VM options (see
TestConventionsinbuildSrc), which you may need to set in your Eclipse launch configuration as well:--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED -Xshare:off
Tips
In any case, please do not check in your own generated .classpath file, .project
file, or .settings folder. You'll notice these files are already intentionally in
.gitignore. The same policy holds for IntelliJ IDEA metadata.