I have inherited a java gradle project and I am trying to get my settings right.

The project can be build with gradle in the windows CLI without problem, however I am not able to get the project to build, run or debug directly in intellij.The gradle build actually compiles 2 seperate java projects. When trying to debug, run or build in intellij the main project throws errors about the second java project that supposedly does not exist ("java: package com.company.packagename does not exist").In the debug/run settings I have set the main class and I have set "Before launch, run gradle task" which is supposed to build both projects (again this works correctly in gradle command line).Clearly I am doing something wrong.Anyone knows what is going wrong?