Guide to Using Boot Add
You can use all the projects that are available in the project list
command to add code and configuration to an existing project.
The CLI does this by:
-
Merging the Maven build file, so that any missing project properties, dependencies, dependency management, and plug-ins are added into the target project.
-
Performing a package refactoring so that the code to be copied into the target project with the same package structure.
-
Adding any missing annotations on the Spring Boot main application in the target project.
-
Renaming the
README.adoc
(or .md) file toREADME-<project-name>.adoc
so that you can describe additional information about what code was added. -
Merging
application.yaml
andapplication.properties
files.
The heuristic to perform this task is not 100% complete at this time, so expect a few bumps if you are an early adopter.
For example, assume we have added the getting started catalog:
spring catalog add gs https://github.com/rd-1-2022/spring-gs-catalog
This gives us the following projects from which to select:
┌──────────┬────────────────────────────────────────────────────────┬────────────────────────────────────────────────────────────────┬───────┬──────────────┐
│Name │URL │Description │Catalog│Tags │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│web │https://github.com/rd-1-2022/rpt-rest-service │Hello, World RESTful web service. │gs │[rest, web] │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│jpa │https://github.com/rd-1-2022/rpt-spring-data-jpa │Learn how to work with JPA data persistence using Spring Data │gs │[jpa, h2] │
│ │ │JPA. │ │ │
├──────────┼────────────────────────────────────────────────────────┼────────────────────────────────────────────────────────────────┼───────┼──────────────┤
│eureka │https://github.com/rd-1-2022/eureka │Spring Cloud Eureka Server │gs │[cloud, │
│ │ │ │ │eureka] │
└──────────┴────────────────────────────────────────────────────────┴────────────────────────────────────────────────────────────────┴───────┴──────────────┘
We can create a new web project and then add JPA functionality to that project by running the following commands:
spring boot new demo web --package-name com.xkcd
cd demo
spring boot add jpa
The project tree now contains both the web application and the JPA functionality:
$ tree
.
├── LICENSE
├── mvnw
├── mvnw.cmd
├── pom.xml
├── README.adoc
├── README-jpa.md
└── src
├── main
│ └── java
│ └── com
│ └── xkcd
│ ├── Application.java
│ ├── customer
│ │ ├── CustomerCommandLineRunner.java
│ │ ├── Customer.java
│ │ └── CustomerRepository.java
│ └── greeting
│ ├── GreetingController.java
│ └── Greeting.java
└── test
└── java
└── com
└── xkcd
├── customer
│ └── CustomerRepositoryTests.java
└── greeting
└── GreetingControllerTests.java
Conventions
To perform an intelligent merge of the code base when you run spring boot add
, the following conventions in the project must be followed:
-
You should place the main
@SpringBootApplication
at the root of the package hierarchy with all other code in subpackages. -
There should be no additional
@Bean
annotations in the@SpringBootApplication
class. Any configuration should live in a separate@Configuration
class.
Limitations
Currently, only single-module Maven projects are supported. Support for single-module Gradle projects is planned for the 1.0 release. No timeline is defined for supporting multi-module projects.