GRadle API providing incorrect build file name when using project.getBuildFile()

Taking an example of an open source repository kafka/build.gradle at trunk 路 apache/kafka 路 GitHub
where single build file generates sub projects.

if you add a task that looks like

task printBuildFile(){
    println "${project.getBuildscript().getSourceFile()}"
    println "${project.getBuildFile()}"
  }


and execute ./gradlew :tools:tools-api:printBuildFile
You will see that it prints the values

/Users/gradleThingies/kafka/tools/tools-api/build.gradle
/Users/gradleThingies/kafka/tools/tools-api/build.gradle

however the above files dont exist.

Please note gradlew projects prints the proper project structure


------------------------------------------------------------
Root project 'kafka'
------------------------------------------------------------

Root project 'kafka'
+--- Project ':clients'
+--- Project ':connect'
|    +--- Project ':connect:api'
|    +--- Project ':connect:basic-auth-extension'
|    +--- Project ':connect:file'
|    +--- Project ':connect:json'
|    +--- Project ':connect:mirror'
|    +--- Project ':connect:mirror-client'
|    +--- Project ':connect:runtime'
|    +--- Project ':connect:test-plugins'
|    \--- Project ':connect:transforms'
+--- Project ':core'
+--- Project ':examples'
+--- Project ':generator'
+--- Project ':group-coordinator'
|    \--- Project ':group-coordinator:group-coordinator-api'
+--- Project ':jmh-benchmarks'
+--- Project ':log4j-appender'
+--- Project ':metadata'
+--- Project ':raft'
+--- Project ':server'
+--- Project ':server-common'
+--- Project ':shell'
+--- Project ':storage'
|    \--- Project ':storage:storage-api'
+--- Project ':streams'
|    +--- Project ':streams:examples'
|    +--- Project ':streams:streams-scala'
|    +--- Project ':streams:test-utils'
|    +--- Project ':streams:upgrade-system-tests-0100'
|    +--- Project ':streams:upgrade-system-tests-0101'
|    +--- Project ':streams:upgrade-system-tests-0102'
|    +--- Project ':streams:upgrade-system-tests-0110'
|    +--- Project ':streams:upgrade-system-tests-10'
|    +--- Project ':streams:upgrade-system-tests-11'
|    +--- Project ':streams:upgrade-system-tests-20'
|    +--- Project ':streams:upgrade-system-tests-21'
|    +--- Project ':streams:upgrade-system-tests-22'
|    +--- Project ':streams:upgrade-system-tests-23'
|    +--- Project ':streams:upgrade-system-tests-24'
|    +--- Project ':streams:upgrade-system-tests-25'
|    +--- Project ':streams:upgrade-system-tests-26'
|    +--- Project ':streams:upgrade-system-tests-27'
|    +--- Project ':streams:upgrade-system-tests-28'
|    +--- Project ':streams:upgrade-system-tests-30'
|    +--- Project ':streams:upgrade-system-tests-31'
|    +--- Project ':streams:upgrade-system-tests-32'
|    +--- Project ':streams:upgrade-system-tests-33'
|    +--- Project ':streams:upgrade-system-tests-34'
|    +--- Project ':streams:upgrade-system-tests-35'
|    +--- Project ':streams:upgrade-system-tests-36'
|    \--- Project ':streams:upgrade-system-tests-37'
+--- Project ':tools'
|    \--- Project ':tools:tools-api'
+--- Project ':transaction-coordinator'
\--- Project ':trogdor'


However the above files do not exists.

Please help, how can i get proper build file name

You did get the proper build file name.
That it does not exist is irrelevant, it is treated the same as if the file were there but empty.
That project is using bad-practice discouraged cross-project configuration, having the build logic (or at least a part) in the root projects build script, cross-configuring all projects, so there is no logic left for that project鈥檚 build script itself and thus it can also just be omitted.

1 Like