Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intelij: Cannot import classes from other modules in my project?

My Application consists of multiple Java modules, built with Gradle.

I have created a new module within it and I cannot import any classes from the other modules. I am quite new to Gradle/Java so perhaps Im missing something very obvious.

When I attempt to import a class I get the following error:

"Cannot resolve symbol [import class name]"

What can I do to resolve this? Do I need to alter my build.gradle scripts? Could it be my package structure?

Note: I am able to import standard java libraries, such as

java.util.HashMap

My Build.gradle is just the following:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'application'
like image 243
java123999 Avatar asked Oct 31 '22 09:10

java123999


1 Answers

In order to make an import one module into another, you have to provide a module dependencies in your build script. You can read about it in the official documentation here and here.

All you need to do, is to provide defined project structure with the settings.gradle file in the root. And then add the dependencies section to the module, in which you need to import something, like:

dependencies {
    compile project(':shared')
}
like image 72
Stanislav Avatar answered Nov 15 '22 04:11

Stanislav