Adding dependencies to existing project via Spring CLI

Viewed 1038

Is there any way to add dependencies to existing spring project using Spring CLI (for instance via shell)?

I tried to looked for on this website docs.spring.io.

But I couldn't find working way of adding dependency like Spring Web or Spring Data JPA to existing spring project.

3 Answers

If you are using STS or Eclipse for your development then you can easily add dependencies using CLI.
You need to press the Ctrl+Space Bar in your pom.xml.
It will show you the option with Edit starters as shown below, then click on it it will open your CLI interface

Ctrl+Space Bar Ctrl+Space Bar

CLI interface

You can use pom.xml to add dependencies to your existing spring project whether you created your project by using Spring CLI or any other way.

  1. Go to Maven Repository: https://mvnrepository.com/
  2. Search for your required dependencies
  3. Copy the dependency for maven and paste it in your pom.xml

To add a dependancy from Spring CLI, you can use the following command:

spring init -a <name_of_your_artifact> --dependencies=web,data-jpa <my_project>

where:

<name_of_your_artifact>: the artifact Id for the project.

and

<my_project>: name of the file where the .zip of spring initilizer will be extractred.

Related