PacktPublishing / Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud

Hands-On Microservices with Spring Boot and Spring Cloud, published by Packt
MIT License
464 stars 406 forks source link

Project Structure Issue leads to Inability to compile with Intellij #13

Closed cgerard321 closed 3 years ago

cgerard321 commented 3 years ago

Hello,

This isn't so much an issue as perhaps a question about something that is not discussed in the book, namely, how do we create the project structure you have in your source code? For example, if I open Chapter05 in intellij and look at the project structure, it shows:

chapter5projstruct

By the project structure I get looks like this (I've played around with it and sometimes get a slightly different structure such as one where all the projects are on the same level):

myprojstruct

The result is that when gradle tries to sync in the IDE (Intellij Ultimate), I get the following error for every service:

A problem occurred evaluating root project 'product-service'.

Project with path ':api' could not be found in root project 'product-service'.

Would it be possible to give some references as to how to correctly build the project structure? I'm not very familiar with Gradle or Modules in general.

Note: regardless of this, I am able to build and run via the command-line. It's just it would be very helpful to be able to get this to work in the IDE as it is preventing me from getting Swagger to work in Chapter 5 since the libraries aren't getting pulled in (due to Gradle not syncing).

Thank you! Christine

Miles-Ahead-Digital commented 3 years ago

Check if this works:

-you need the gradle wrapper in each module -delete the module -add the module again by using context menu "module setting" --> "+" --> "import module" --> navigate to the module folder

magnus-larsson commented 3 years ago

Hello Christine!

Sorry for a late response!

The chapters in the book follows the standard layout for Gradle multi-projects, so Intellij should be able to resolve the dependencies out of the box.

Can you repeat the following steps to verify that is works as expected? I'm using chapter 14 as an example since it is the chapter that contains most Spring Boot modules, i.e. have the highest complexity from a dependency perspective.

  1. Checkout the code and build it from the command prompt:
git clone https://github.com/PacktPublishing/Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud.git
cd Hands-On-Microservices-with-Spring-Boot-and-Spring-Cloud/Chapter14
./gradlew build
  1. Import the code into IntelliJ 2.1. Select from the menu: "File --> New --> Project from Existing Sources..." 2.2 Navigate to and select the folder Chapter14 2.3 Import Project from external model --> Gradle 2.4 Then you wait for IntelliJ to resolve all dependencies...

You should now be able to see all projects correctly detected and resolved by IntelliJ:

Screenshot 2021-02-06 at 11 08 32

I'm using IntelliJ Ultimate 2020.3.2, but I don't think it matters, IntelliJ has always done a great job on resolving Java projects built with either Maven or Gradle!

Please, let me know if this works for you or if you run into any issues!

Regards, Magnus.