Integration of gradle-oci and junit-jupiter
Use the Gradle OCI Plugin and add the dependency on gradle-oci-junit-jupiter
in your build.gradle(.kts)
:
plugins {
java
id("io.github.sgtsilvio.gradle.oci") version "0.22.0"
}
repositories {
mavenCentral()
}
oci {
registries {
dockerHub {
optionalCredentials()
}
}
}
testing {
suites {
"test"(JvmTestSuite::class) {
useJUnitJupiter()
dependencies {
implementation("io.github.sgtsilvio:gradle-oci-junit-jupiter:0.7.0")
}
oci.of(this) {
imageDependencies {
runtime("your:image:123")
}
}
}
}
}
On MacOS and Windows host.docker.internal
needs to be configured as an insecure registry in the Docker daemon configuration.
Usually, host.docker.internal
resolves to the address 192.168.65.254
.
{
"insecure-registries": [
"192.168.65.254/32"
]
}
Your Docker subnet may be configured differently.
You can determine the IP address by resolving the domain name host.docker.internal
inside a container using this command:
docker run --rm busybox nslookup host.docker.internal
Example in Java:
class ContainerTest {
@Test
void start() {
try (final GenericContainer<?> container = new GenericContainer<>(OciImages.getImageName("your/image:123"))) {
container.start();
//...
}
}
}