2

I am struggling to execute gradle tasks from a subproject when using buildSrc.

The project structure looks like this:

root
 buildSrc
  src
   main
    kotlin
     Dependencies.kt
  build.gradle.kts
 soa
  SoaProject1
   settings.gradle.kts
   build.gradle.kts
  SoaProject2
   settings.gradle.kts
   build.gradle.kts
 tools
  ToolProject1
  ToolProject2
 settings.gradle.kts
 build.gradle.kts

The root settings.gradle.kts looks like this:

include(
    ":SoaProject1",
    ":SoaProject2"
)
project(":SoaProject1").projectDir = File("soa/SoaProject1")
project(":SoaProject2").projectDir = File("soa/SoaProject2")

In one of the build.gradle.kts files of a SoaProject e.g. I have following dependency:

dependencies {
  implementation("log4j:log4j:${Versions.log4j}")
}

Importing/Refreshing gradle projects is working in Intellij and the dependencies get downloaded. But when I try to execute a gradle task from the subproject I get an unresolved reference Versions error.

The Dependencies.kt contains the Versions class and it looks like this:

object Versions {
  const val log4j = "1.2.16"
}

So to me it looks like gradle can find the dependencies and the Versions class but for some reason the tasks of the subproject don't have access to the buildSrc?

Does anyone have any hint what might be missing or what I can try?

Thank you for your help!

Regards Simon

Simon
  • 148
  • 3
  • 13
  • Please check this thread https://stackoverflow.com/questions/26509427/execute-gradle-task-on-sub-projects – Andrey Feb 20 '20 at 09:45
  • thanks but unfortunately it did not help me. However, I did notice that when the "intermediate" folder also becomes a project by adding a gradle.build.kts file it seems to work. Maybe subprojects are confused if the parent is not directly one level above? – Simon Feb 21 '20 at 16:55

1 Answers1

0

Sorry for the late reply but the problem got solved as you can see in the comments of the first post.

The issue is, that when you have a multiproject setup then gradle is scanning the folders hierarchical. Every subfolder of the root project that is relevant for the gradle multiproject needs to contain a build.gradle / build.gradle.kts file, even if it is empty.

That way, everything is working well and at least in IntelliJ the gradle support is working well and modules are created correctly.

Simon
  • 148
  • 3
  • 13