dasniko/testcontainers-keycloak

WithProviderClassesFrom does not work with gradle.

sillen102 opened this issue · 7 comments

Describe the bug

.withProviderClassesFrom("target/classes") is not working with Gradle. I get ERROR: No such provider when Keycloak starts. I have also tried with "build/classes" since the build is generating a build folder in project root, but that doesn't work either.

This is my setup for the container:

@Container
private static final KeycloakContainer keycloak = new KeycloakContainer("quay.io/keycloak/keycloak:22.0.1")
            .withRealmImportFile("/my-realm.json")
            .withProviderClassesFrom("target/classes")
            .withNetwork(network);

Version

3.0.0

Expected behavior

That the provider is found.

Actual behavior

The provider cannot be found.

How to Reproduce?

No response

Relevant log output

No response

Anything else?

No response

There's a current PR trying to fix this, please test with #112 and give some feedback if this solves your issue, thanks.

I tried it (the code in the merge request). Couldn't get it to work. I tried with "build/classes/java/main", "build/classes" and "target/classes".

I think I'm just going to go with Maven for this project as it seems to be working and it's a simple setup with few dependencies.

Thanks for the quick response though! As soon as there's a fix I'll be switching to Gradle again.

Removed the bug label, as it was not yet designed to work with Gradle. It's more of a kind of enhancement, like a new feature.

@sillen102 I don't have experience with Gradle, so I can't support something valueable here. Perhaps @objecttrouve can help here, as he provided #112 !?

@sillen102, it's possible to work around the issue by importing the extension via the withProviderLibsFrom-method instead of the withProviderClassesFrom-method.

It's just less convenient and requires you to create the jar or shaded jar before running the tests. This can be done in the build script by making the test task dependent on the jar or shadow task. Also, one should ensure that the build directory is always cleaned up first.

Ususlly you can find the .jar in the build/libs directory.

fkowal commented
# build.gradle.kts
tasks.withType<Test> {
    dependsOn("jar")
}

# myTest
@Container
private val keycloak = KeycloakContainer(...)
.withProviderLibsFrom(listOf(File("build/libs/{modulename}.jar")))

this seem work fine 4 gradle

Closing this, as there are viable workarounds mentioned, also in #112