micronaut-projects / micronaut-starter

Generates Micronaut applications
Apache License 2.0
213 stars 96 forks source link

Dependency has wrong scope - testRuntimeOnly instead of testImplementation #588

Closed sascha-frinken closed 3 years ago

sascha-frinken commented 3 years ago

When creating a project via micronaut starter with testcontainers and mariadb features it creates following gradle dependencies.

dependencies {
    implementation("io.micronaut:micronaut-validation")
    implementation("io.micronaut.groovy:micronaut-runtime-groovy")
    implementation("javax.annotation:javax.annotation-api")
    implementation("io.micronaut:micronaut-http-client")
    runtimeOnly("ch.qos.logback:logback-classic")
    runtimeOnly("org.mariadb.jdbc:mariadb-java-client")
    testRuntimeOnly("org.testcontainers:mariadb")
}

testRuntimeOnly("org.testcontainers:mariadb") should be testImplementation("org.testcontainers:mariadb")

jameskleeh commented 3 years ago

@sascha-frinken Why do you think so? What use case do you have for it to be on the compile classpath?

sascha-frinken commented 3 years ago

Because it doesn't work. Even the testcontainers documentation samples use testImplementation.

If it helps I will create a sample app.

wetted commented 3 years ago

If one is using testcontainers with SQL-like databases, the testcontainers JDBC/R2DBC built-in support can be utilized; i.e. the testcontainer-modified URL scheme ( e.g. jdbc:tc:mysql:…) along with the @MicronautTest embedded server. In that case the testcontainer dependency should work with the testRuntimeOnly scope. The micronaut-starter project has integration tests that do just that: create and test projects for the SQL-like databases, and they run fine.

However, if one wants to instantiate a testcontainer Container object and wire it manually with the Micronaut embedded server, then the dependency needs to be testImplementation. It's a bit more involved to do it that way, but that's necessary for the NoSQL database testcontainers. I am adding this for mongodb on Issue #614 where it's necessary, so I plan to also change the dependencies for the SQL-like database testcontainers to testImplementation as well. As it is I'm also adding support for testcontainer junit/spock annotations and those dependencies expose the testcontainers core dependency as testImplementation anyway.