Skip to content

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

Open
Niloyyy wants to merge 1 commit into
openrewrite:mainfrom
Niloyyy:gate-no-repositories-test-on-mirror
Open

Gradle: disable the no-repositories metadata test only when a mirror is injected#8664
Niloyyy wants to merge 1 commit into
openrewrite:mainfrom
Niloyyy:gate-no-repositories-test-on-mirror

Conversation

@Niloyyy

@Niloyyy Niloyyy commented Aug 26, 2026

Copy link
Copy Markdown

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

1 participant