Skip to content

Gradle: disable the no-repositories metadata test only when a mirror is injected - #8664

Merged
timtebeek merged 2 commits into
openrewrite:mainfrom
Niloyyy:gate-no-repositories-test-on-mirror
Sep 21, 2026
Merged

timtebeek merged 2 commits into
openrewrite:mainfrom
Niloyyy:gate-no-repositories-test-on-mirror

Conversation

@Niloyyy

@Niloyyy Niloyyy commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What's changed?

  • UpgradeDependencyVersionTest.cannotDownloadMetaDataWhenNoRepositoriesAreDefined has carried a blanket @Disabled since Provide Artifactory credentials to CI #7566, so it runs nowhere — not in CI, and not for anyone building without a mirror configured. It's the last @Disabled("...temporarily disabled after Artifactory introduction") left in rewrite-gradle.

  • This swaps it for the conditional disable that Provide Artifactory credentials to CI #7566 already applied to the two tests in the same situation.

Why it fails under a mirror

The test asserts that a build file declaring no repositories produces an Unable to download metadata marker. When REWRITE_GRADLE_MIRROR_URL / _USERNAME / _PASSWORD are all set, OpenRewriteModelBuilder.mirrorScriptSnippet() prepends the mirror to project.repositories via gradle.beforeProject:

gradle.beforeProject { project ->
    __rewriteAddMirror(project.buildscript.repositories)
    __rewriteAddMirror(project.repositories)
}

So the embedded build no longer has zero repositories, guava metadata resolves, and the recipe upgrades instead of marking. Simply deleting the @Disabled reddens CI — with the mirror env set locally (pointed at Maven Central, standing in for Artifactory):

UpgradeDependencyVersionTest > cannotDownloadMetaDataWhenNoRepositoriesAreDefined() FAILED
    org.opentest4j.AssertionFailedError: [Unexpected result in "build.gradle":
    @@ -3,5 +3,5 @@
     dependencies {
    -  /*~~(com.google.guava:guava failed. Unable to download metadata.)~~>*/implementation "com.google.guava:guava:29.0-jre"
    +  implementation "com.google.guava:guava:30.1.1-jre"
     }
  • That is exactly the situation EffectiveGradleRepositoriesTest.emptyRepositories and FindRepositoryOrderTest.emptyRepositories are in, and Provide Artifactory credentials to CI #7566 gave those two a conditional disable rather than a blanket one. This applies the same annotation, reusing their disabledReason verbatim because the scenario is identical.

What it costs

This does not make the test run in CI. CI always sets the mirror, so it stays skipped there — same as the two emptyRepositories tests. What it buys is that the test runs for every contributor and downstream build without a mirror, instead of being dead everywhere.

If you'd rather have the scenario covered in CI too, the alternative is to make the assertion tolerate an injected repository (or to suppress injection for this one build), which is a larger change to OpenRewriteModelBuilder — happy to take that on instead if you prefer it.

Tests

Verified all four combinations locally on f90af07:

annotation REWRITE_GRADLE_MIRROR_URL result
@Disabled (before) unset or set skipped — never runs
removed unset passes
removed set fails (output above)
@DisabledIfEnvironmentVariable (after) set skipped
@DisabledIfEnvironmentVariable (after) unset passes

The middle two are the point: the test is sound off-mirror, and the guard is doing real work rather than being decorative.

The full UpgradeDependencyVersionTest class passes with the change: 110 tests, 0 failures, 0 errors, 0 skipped (no mirror configured, so the guarded test runs).

Any additional context

…is injected

cannotDownloadMetaDataWhenNoRepositoriesAreDefined has carried a blanket
@disabled since openrewrite#7566, so it runs nowhere -- not in CI, and not for anyone
building without a mirror configured.

It fails under a mirror for a specific reason: the test asserts that a build
file declaring no repositories produces an "Unable to download metadata"
marker, and OpenRewriteModelBuilder.mirrorScriptSnippet() prepends the mirror
to project.repositories via gradle.beforeProject when the mirror env vars are
set. The build then has a repository, guava metadata resolves, and the recipe
upgrades to 30.1.1-jre instead of marking.

That is the same situation EffectiveGradleRepositoriesTest.emptyRepositories
and FindRepositoryOrderTest.emptyRepositories are in, so use the conditional
disable openrewrite#7566 gave those two, reusing their disabledReason verbatim. The test
stays skipped in CI and runs everywhere else.
@Niloyyy

Niloyyy commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Hey @timtebeek — you approved CI on #8666 a couple of weeks back and it came back green, but this one's never had a run, so it's been sitting here untested.

Any chance you could kick off the workflows? And if the blanket @Disabled is deliberate, just say so and I'll close this — genuinely no problem either way.

The change is one annotation. cannotDownloadMetaDataWhenNoRepositoriesAreDefined is disabled outright, so right now it runs nowhere at all. I swapped it for the @DisabledIfEnvironmentVariable(named = "REWRITE_GRADLE_MIRROR_URL", ...) guard that #7566 already put on the two emptyRepositories tests — same situation, the injected mirror adds a repository and "no repositories declared" quietly stops being true.

One heads-up so the run doesn't look odd: it stays skipped in CI either way. What this buys is the test coming back for anyone building without a mirror.

@timtebeek timtebeek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spotting and fixing this @Niloyyy ! I was out on holiday for three weeks, hence why it's taken me a little longer to get to review. I'll merge as soon as CI checks succeed.

@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite Sep 21, 2026
@timtebeek
timtebeek merged commit 9791de9 into openrewrite:main Sep 21, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite Sep 21, 2026
@Niloyyy

Niloyyy commented Sep 21, 2026

Copy link
Copy Markdown
Contributor Author

@timtebeek it's okay btw I was waiting for your review. Anyway thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants