Skip to content

Fix jarFileTest cache relocatability#11574

Merged
eddumelendez merged 2 commits intotestcontainers:mainfrom
ribafish:fix-jarfiletest-cache-relocatability
Mar 24, 2026
Merged

Fix jarFileTest cache relocatability#11574
eddumelendez merged 2 commits intotestcontainers:mainfrom
ribafish:fix-jarfiletest-cache-relocatability

Conversation

@ribafish
Copy link
Contributor

@ribafish ribafish commented Mar 19, 2026

Problem

The jarFileTest task sets systemProperty("jarFile", shadowJar.outputs.files.singleFile) which embeds an absolute path as a task input. This makes the task not cache-relocatable — when run from a different project location, the cache key changes even though the actual jar content is identical.

Additionally, the file(shadowJar.outputs.files.singleFile) call doesn't actually register a proper task input with Gradle's input tracking.

This is an example cache miss because of this issue.

Fix

  1. Replace file(...) with inputs.files(shadowJar).withPathSensitivity(PathSensitivity.RELATIVE) — properly registers the shadow jar as an input with relative path normalization
  2. Pass the jar path as a relative path (project.projectDir.relativize(jarFile)) to the system property — produces build/libs/testcontainers-<version>-all.jar instead of /home/user/project/core/build/libs/...

AbstractJarFileTest uses Paths.get(System.getProperty("jarFile")) which resolves relative paths against the working directory (project dir by default), so the test works identically.

Here is a run against this branch, verifying the fix and the overall build.

The jarFileTest task sets `systemProperty("jarFile", absolutePath)` which
embeds an absolute path as a task input, making the task not
cache-relocatable across different project locations.

Fix by:
- Using `inputs.files(shadowJar).withPathSensitivity(RELATIVE)` instead
  of the bare `file()` call (which doesn't register a proper input)
- Passing the jar path as a relative path to the system property

The test (AbstractJarFileTest) uses `Paths.get(System.getProperty("jarFile"))`
which resolves relative paths against the working directory (project dir),
so the test works identically with both absolute and relative paths.
@ribafish ribafish requested a review from a team as a code owner March 19, 2026 09:10
ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 19, 2026
Point workflow at ribafish/testcontainers-java fork with the fix branch
to validate the upstream PR (testcontainers/testcontainers-java#11574).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 19, 2026
Bump JDK 11→17, exclude failing VolumeRemoval tests, and mark
jarFileTest as non-cacheable (absolute path in systemProperty).

Upstream fix: testcontainers/testcontainers-java#11574
@eddumelendez eddumelendez added this to the next milestone Mar 24, 2026
@eddumelendez eddumelendez merged commit 9665322 into testcontainers:main Mar 24, 2026
102 checks passed
@eddumelendez
Copy link
Member

Thanks for your contribution, @ribafish !

ribafish added a commit to gradle/develocity-oss-projects that referenced this pull request Mar 25, 2026
Bump JDK 11→17, exclude failing VolumeRemoval tests, and mark
jarFileTest as non-cacheable (absolute path in systemProperty).

Upstream fix: testcontainers/testcontainers-java#11574
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants