gradle multi-project: build directory appears in root dir containing Kotlin artefacts

Viewed 835

Our multi-project build has the following structure:

root-project \-project1 \-project2 \-build.gradle \-settings.gradle

When I run a gradle build from the root-project directory the build artefacts in project1 (not a Kotlin project) remain under the project1/build directory as expected. However, a build directory appears under the root-directory containing only build/kotlin and build/kotlin-build directories.

Even if I run gradle build from root-project/project2 I see the same behaviour.

What am I missing to order force all of the kotlin build artefacts to be placed under:

root-dir/project2/build

I have the following in my root-dir/build.gradle which may be shed some light on the behaviour:


    task root-project(dependsOn: ':project1:build') {
       doLast {
           copy {
               from project(':project1:').file('dist')
               into project(':project2:').file('build/resources/main/static/')
           }
       }
    }

    project(':project1') {
        task UI(dependsOn: ':project1:runAll') {
            doLast {
                println 'UI'
            }
        }
    }

    project(':project2') {
        task API(dependsOn: ':project2:bootRun') {
            doLast {
                println 'API'
            }
        }
    }

1 Answers

The resulting artifacts are actually placed under the subproject directories, quite as you expect.

The build/kotlin and build/kotlin-build directories in the root project contain some internal state that the Kotlin Gradle plugin stores and uses across builds (such as multi-module incremental compilation cache). It's placed under the root project directory, because it is also shared across the subprojects.

In other words, it's not something to worry about.

Related