-
Notifications
You must be signed in to change notification settings - Fork 41k
Restructuring
Create the directory structure for the new project:
mkdir -p spring-boot-project/spring-boot-new-project/src/main/java mkdir -p spring-boot-project/spring-boot-new-project/src/main/resources mkdir -p spring-boot-project/spring-boot-new-project/src/test/java mkdir -p spring-boot-project/spring-boot-new-project/src/test/resources
Create the build.gradle
file:
touch spring-boot-project/spring-boot-new-project/build.gradle
Or if you’re feeling brave a one-liner:
module="spring-boot-quartz" && (for f in "main/java" "main/resources" "test/java" "test/resources";\ do mkdir -p "spring-boot-project/$module/src/$f"; done && touch spring-boot-project/$module/build.gradle)
The following is a reasonable starting point for its content.
You may also want to look at the relevant starter to identify additional dependencies.
Consider carefully the use of api
, implementation
, and optional
.
plugins { id "java-library" id "org.springframework.boot.auto-configuration" id "org.springframework.boot.configuration-properties" id "org.springframework.boot.deployed" id "org.springframework.boot.optional-dependencies" } description = "Spring Boot New Project" dependencies { api(project(":spring-boot-project:spring-boot")) optional(project(":spring-boot-project:spring-boot-autoconfigure")) testImplementation(project(":spring-boot-project:spring-boot-test")) testImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support")) testRuntimeOnly("ch.qos.logback:logback-classic") }
Edit settings.gradle
to include the new project.
Edit spring-boot-project/spring-boot-dependencies/build.gradle
to add the new project to the Spring Boot library.
Edit the build.gradle
of the relevant starter(s) to depend on the new project.
Create the auto-configuration imports file:
mkdir -p spring-boot-project/spring-boot-new-project/src/main/resources/META-INF/spring touch spring-boot-project/spring-boot-new-project/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports
Edit spring-boot-project/spring-boot-docs/build.gradle
to add autoConfiguration
and configurationProperties
dependencies for the new project.
Refresh your IDE to import the new project.
Move code and resources from spring-boot-all
and spring-boot-autoconfigure-all
into the new project.
Check main
, test
and, if applicable, dockerTest
.
There will now be many compile errors.
If the new project has compile errors in main code, fix them by adding dependencies to it.
Consider carefully the use of api
, implementation
, and optional
as you do so.
If the new project has compile errors in test code, fix them by adding dependencies to testImplementation
.
If a failure is due to a test using some common code or base class, add a testFixtures(project("spring-boot-project-with-required-test-fixtures"))
dependency.
Existing projects will have compile errors.
If spring-boot-all
has compile errors, fix them by moving more code into the new project or by reworking the code to break the link.
Otherwise, fix them by adding project("spring-boot-new-project")
dependencies as needed, most likely in the optional
or testImplementation
configuration.
Dependencies in spring-boot-docs
should be added to implementation
.
Once there are no compile errors, rename the packages in the new project.
The root package should align with the project’s name.
Auto-configuration should be placed in an autoconfigure
sub-package.
Update the @since
javadoc for any code that has changed package.
The top-level class should be @since 4.0.0
.
Remove @since
from any methods or inner-classes.
There should continue to be no compile errors at this point.
If you’re using an IDE that does not understand Kotlin, check if any Kotlin snippets in spring-boot-docs
need to be updated.
Review any code affected by any auto-configurations moving to the new module and changing package.
If the new module will not always be present, change the @AutoConfiguration
before
or after
attributes that reference one of its auto-configuration to use beforeName
and or afterName
instead.
This is necessary to prevent a failure at runtime when processing an annotation that references by type a class that cannot be loaded.
Run ./gradlew checkSpringFactories checkAotFactories checkArchitectureMain autoConfigurationMetadata --continue
.
Correct any problems that it reports.
This may require changes to auto-configuration imports, AOT factories and Spring factories metadata in both the new project and the existing projects from which it was extracted.
Check additional-spring-configuration-metadata.json
in the existing projects from which code was extracted.
Move any metadata for properties in the new project into the new project.
With all the code changes made, it’s time to tidy up and check things are working.
The renamed packages may have affected import ordering.
In Eclipse, Source → Organize Imports
and Source → Clean up…
can help with this.
Changes in package names may also have affected formatting. ./gradlew format
can help with this.
Build the new project (./gradlew spring-boot-project:spring-boot-new-project:build
).
Fix any errors.
Run a full build (./gradlew build
).
Fix any errors.
Commit the changes with a message similar to Create spring-boot-new-project module
.
Push.