15

Gradle: how to get default resources output dir?

println sourceSets.main.resources.outputDir

Error:

Needs to set a non-null value before it can be retrieved
eastwater
  • 4,624
  • 9
  • 49
  • 118

2 Answers2

24

Try this :

println sourceSets.main.output.resourcesDir

Source

ToYonos
  • 16,469
  • 2
  • 54
  • 70
  • Link to docs: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.SourceSetOutput.html – Jason Dec 27 '21 at 17:39
4

For kotlin DSL:

sourceSets.main.get().output.resourcesDir
hongwingl
  • 41
  • 2
  • `sourceSets.main.get().output.resourcesDir` is a `File` type. To cast it to String, we should call `sourceSets.main.get().output.resourcesDir.toString()` – shen Jan 18 '22 at 17:05