简体   繁体   中英

Include package from another project Spring boot gradle Intellij

I have two spring boot gradle projects in Intellij - Project1 and Project2. I'd like to import and use classes from Project2 in Project1. What is the bst way to do this? So far I have not been able to get this to work and I'm not sure the best way to do this. Probably the best way would be to include Project2 as a dependency inside of Project1's build.gradle - but I don't have a maven repository right now.

What I've tried is - I've tried editing Project1 project structure and adding Project2 as a Module. This doesn't seem to work - I get 'cannot resolve symbol' errors when trying to import packages from Project2 in Project1. Not sure this is the best way either.

I've also tried -

include "Project2"

in Project1 settings.gradle

and

...
dependencies {
  compile project(":Project2")
  ...
}

in Project1 build.gradle - this doesn't seem to work either. I get errors when trying to import packages from Project2 in Project1. Not sure this is the best way either. I get 'cannot resolve symbol' errors when trying to import packages from Project2 in Project1. Not sure this is the best way either.

How would you do this? Any ideas on the errors I'm getting?

Thanks for any advice.

You should change how the projects folder structure is. I suggest something like this:

>projects
   >Project1
       build.gradle
   >Project2
       build.gradle
   settings.gradle
   build.gradle

Into settings.gradle you should add all the projects, like this:

include 'Project1'
include 'Project2'

And into Project1 build.gradle this:

...
dependencies {
  compile project(":Project2")
  ...
}

You can find more information about Multi-project Builds in Gradle here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM