dasniko / testcontainers-keycloak

A Testcontainer implementation for Keycloak IAM & SSO.
Apache License 2.0
327 stars 50 forks source link

WithProviderClassesFrom does not work with gradle. #115

Closed sillen102 closed 8 months ago

sillen102 commented 10 months ago

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

dasniko commented 10 months ago

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

sillen102 commented 10 months ago

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.

dasniko commented 10 months ago

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.

dasniko commented 10 months ago

@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 !?

objecttrouve commented 9 months ago

@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 9 months ago
# 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

dasniko commented 8 months ago

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