Hi
I have two Java projects, J1
and J2
, both are subprojects.
In J1
's test suite I use testcontainers, and I want to run up J2
in a docker image.
Therefore I want J1
's tests to depend on J2
's docker image.
I can make J2
image be built, but I really want it only to be built when J1
needs it as a test dependency:
Expected:
./gradlew j1:test
(builds J2’s docker image)
./gradlew j1:build -x test
(does not built J2’s docker image)
Please can anyone discuss how best to model this? As an artifact into a producer configuration out from J2
? And then consumed like the above in J1
?
My solution so far:
In J1
:
dependencies {
testRuntimeOnly(
project(path: ":j2", configuration: "serviceDockerImage")
)
}
In J2
:
artifacts {
serviceDockerImage(File.createTempFile("dockerTempFile-${project.name}", "tmp")) {
builtBy createServiceDockerImage (... this is elsewhere, works well, depends on shadowJar)
}
}
The problem with the above is that the J2
's docker image is built all the while, apparently in assemble
. But I only want it built when test dependency requires it because it takes time.
Any ideas?