spring-projects / spring-boot

Spring Boot
https://spring.io/projects/spring-boot
Apache License 2.0
74.75k stars 40.59k forks source link

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

Closed doljae closed 4 days ago

doljae commented 4 days ago

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

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

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.

wilkinsona commented 4 days ago

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.

doljae commented 4 days ago

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 🥲

wilkinsona commented 4 days ago

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.

doljae commented 3 days ago

Thanks for your kind explanation @wilkinsona 🙂