Skip to content

Different path to find docker compose in a multi-module project when it is a test #42488

@doljae

Description

@doljae

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions