PacktPublishing / Microservices-with-Spring-Boot-and-Spring-Cloud-2E

Microservices-with-Spring-Boot-and-Spring-Cloud-2E, Published by Packt
MIT License
237 stars 260 forks source link

Gradle error (Project with path ':api' could not be found in root project 'util'.) #11

Closed junh-ki closed 2 years ago

junh-ki commented 2 years ago

I am trying to build the util project on the page 68. I keep getting the build error:

Build file '/Users/junhyungki/Desktop/microservices/util/build.gradle' line: 21

A problem occurred evaluating root project 'util'.
> Project with path ':api' could not be found in root project 'util'.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

if I add include ':api' in settings.gradle, it will throw a different error:

Could not determine the dependencies of task ':compileJava'.
> Could not resolve all task dependencies for configuration ':compileClasspath'.
   > Could not resolve project :api.
     Required by:
         project :
      > No matching configuration of project :api was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally but:
          - None of the consumable configurations have attributes.

I am stuck here. How can I proceed?

junh-ki commented 2 years ago

I am building with IntelliJ

magnus-larsson commented 2 years ago

Hello!

Working with gradle-projects in IntelliJ can be a painful experience, there are many ways to set it up incorreclty :-(

The gradle is set up as a multi-project, so to build the util project only, from a command promt you can run the command:

 ./gradlew :util:build

Assuming the you are in the top-folder of the specific code base. For the final solutoin for chapter 3, that is: .../Chapter03/2-basic-rest-services.

Can you start with verifying that it works to compile the util-project from the command like as described above?

Next, import the Chapter03/2-basic-rest-services - project into IntelliJ by taking the following steps:

  1. File -> New -> Project from Existing Sources...
  2. Navigate to the folder .../Chapter03/2-basic-rest-services and select it
  3. Chose "Import porject from exrternal model" and select Gradle
  4. Click on "Finish"

This should result in a successful build and the resulting tree structure should be visible in the Project window:

Screenshot 2022-05-06 at 11 24 16

I'm using IntelliJ IDEA 2021.3.3 (Ultimate Edition).

Hope it helps, regards Magnus.

magnus-larsson commented 2 years ago

Since I haven’t received any questions related to my suggested solution, I’ll close the issue.

junh-ki commented 2 years ago

I was progressing with your version of code but will try this. Sorry about my late reply and thank you for the detailed answer!