Currently we have the following project structure:
root
|_____ api
|_____ common
|______ repository
|_______ src
|_____ main
|_______ kotlin
|_______ sql
|____ init.sql
|_____ test
|_______ kotlin
|_______ ...
|____ Test.kt
|_______ build.gradle.kts
|______ test-utils
|_________ src
|_______...
|_____ package
|________ TestDataSourceConfiguration.kt
|______ ...
|_____ runner
|______ src
|_____ test
|______ ...
|____ TestRunner.kt
TestDataSourceConfiguration.kt creates connection to h2 database with init script from init.sql.
@TestConfiguration
@PropertySource("classpath:database-test.properties")
open class TestDataSourceConfiguration(
@Autowired private val environment: Environment,
) {
@Bean
open fun dataSource(): DataSource {
....
val url = "jdbc:h2://~test;INIT=RUNSCRIPT FROM 'src/main/sql/init.sql'"
....
}
So this works good in Test.kt, but when run tests from TestRunner.kt it fails, because user.dir points to root/runner and init.sql can't be found
I was trying to set for all subprojects new property which points to the root directory of a rootProject... but no avail
Any thoughts how to do this properly?