Description

Hello. I have noticed that the way I find the docker-compose.yml file in a multi-module project is different in normal and test situations.

Reproduce

Spring Boot version

  • 3.3.4

Build script

dependencies {
    implementation("org.springframework.boot:spring-boot-starter")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    testAndDevelopmentOnly("org.springframework.boot:spring-boot-docker-compose") // for docker compose
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testImplementation("org.jetbrains.kotlin:kotlin-test-junit5")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

application.yml

spring:
  docker:
    compose:
      file: docker/docker-compose.yml
      lifecycle-management: start_and_stop
      skip:
        in-tests: false

Gradle project structure

├── README.md
├── docker
│   └── docker-compose.yml -> docker compose file
├── spring-mvc
│   ├── build.gradle.kts
│   └── src -> SpringBootApplication class

Result

  • I put a breakpoint in the DockerComposeFile.of(File file) method and debugged it

  • file.getAbsolutePath()

  • non test case: PROJECT_ABSOLUTE_PATH/docker/docker-compose.yml -> works fine
  • test case: PROJECT_ABSOLUTE_PATH/spring-mvc/docker/docker-compose.yml -> IllegalArgumentException with Docker Compose file 'docker/docker-compose.yml' does not exist

Conclusion

When reading the docker compose file location set in application.yml in a multi-module project, the path seems to be different when testing and when not testing.

Comment From: wilkinsona

The path is resolved against the current working directory. If the working directory is different in the test and non-test cases then the resolved absolute path will also be different. Without knowing how you're running the two different cases, I can't really comment further but, as things stand, I would guess that this is a duplicate of https://github.com/spring-projects/spring-boot/issues/40512 and you need to adjust your IDE's configuration.

Comment From: doljae

Hello @wilkinsona Thanks to your explanation, I realized that the way I was using before was working because of the default settings in the IDE, even though it is not supported by Spring.

I modified my docker-compose.yml file and related directories to be located inside the module rather than in the root directory and found that it worked fine.

I have one question: what is the difference between the working directory and the application directory? I've been googling but haven't seen a clear answer 🥲

Comment From: wilkinsona

Application directory isn't really defined anywhere which is why we moved away from that term as it's ambiguous and has caused confusion. What we meant was the working directory so that's the term that we now use.

Comment From: doljae

Thanks for your kind explanation @wilkinsona 🙂