Skip to content

Route Maven through Moderne Artifactory cache to avoid HTTP 429 - #95

Merged
Jenson3210 merged 2 commits into
mainfrom
jenson3210/route-maven-through-moderne-cache
May 18, 2026
Merged

Jenson3210 merged 2 commits into
mainfrom
jenson3210/route-maven-through-moderne-cache

Conversation

@Jenson3210

Copy link
Copy Markdown
Contributor

Summary

  • Maven Central started rate-limiting parallel test resolution (HTTP 429), failing CI on many consumers of these reusable workflows (rewrite-dropwizard, rewrite-spring, rewrite-spring-to-quarkus, rewrite-jenkins, rewrite-java-dependencies, rewrite-migrate-java, rewrite-spring, rewrite-micronaut, rewrite-quarkus, rewrite-jackson, …).
  • Adds the mirror configuration that moderneinc/rewrite-java-security has been running inline for a while: route mirrorOf: \"*\" through https://artifactory.moderne.ninja/artifactory/moderne-cache-3/ via s4u/maven-settings-action, and set REWRITE_GRADLE_MIRROR_* env vars on the Gradle build/publish steps so rewrite-core's test-time resolution also goes through the cache.
  • Applied to ci-gradle.yml, ci-gradle-blacksmith.yml, and publish-gradle.yml.
  • The new secrets (artifactory_username/_password, ast_publish_username/_password) are optional; when unset the mirror is consulted anonymously, which is sufficient for any artifact present in the anonymous-readable backing repos of moderne-cache-3.

Validated

Inline rollout earlier today across nine recipe repos, five of which were merged and went green via this exact config:

Follow-up

Once merged, the per-repo workflows that were patched inline should revert to the thin-caller form (single `uses: openrewrite/gh-automation/.github/workflows/ci-gradle.yml@main`) and pick up the mirror automatically. I'll open the revert PRs.

A handful of consumers (rewrite-jenkins, rewrite-java-dependencies, rewrite-jackson, rewrite-migrate-java) failed earlier with HTTP 401 from the mirror — an Artifactory virtual-repo iteration quirk where auth-gated backing repos shadow anonymously-readable ones. That's a server-side config issue in `moderne-cache-3` and doesn't affect the correctness of this PR; it does mean those four repos will continue to fail until the backing-repo order is fixed.

Test plan

  • CI on this PR passes
  • After merge, trigger CI on one consumer repo (e.g. `gh workflow run ci.yml -R openrewrite/rewrite-quarkus`) and confirm the mirror config is applied and no `HTTP 429` appears

Maven Central started rate-limiting parallel test resolution
(HTTP 429), failing CI on many consumers of these reusable
workflows. Add the same mirror configuration `moderneinc/rewrite-
java-security` has been using inline: route `mirrorOf: "*"`
through artifactory.moderne.ninja's moderne-cache-3 via
s4u/maven-settings-action, and set REWRITE_GRADLE_MIRROR_* on
the Gradle build/publish steps so rewrite-core's test-time
resolution also goes through the cache.

Validated by the inline rollout of this configuration across
nine recipe repos earlier today, five of which were merged and
went green: rewrite-dropwizard, rewrite-spring-to-quarkus,
openrewrite/rewrite-spring, rewrite-micronaut, rewrite-quarkus.

Once this lands, the per-repo workflows can revert to the
thin-caller form (single `uses:` to this reusable workflow)
and pick up the mirror automatically. The new secrets
(`artifactory_username`/`_password` for the Maven mirror,
`ast_publish_username`/`_password` for the Gradle mirror)
are all optional; when unset the mirror is consulted
anonymously, which is sufficient for any artifact present in
the anonymous-readable backing repos of moderne-cache-3.
Both the s4u/maven-settings-action mirror and the
REWRITE_GRADLE_MIRROR_* env vars authenticate against the
same Artifactory instance (artifactory.moderne.ninja).
Drop the ast_publish_* duplicate and reuse artifactory_*
for both. Optional; anonymous is still supported when unset.
@github-project-automation github-project-automation Bot moved this from In Progress to Ready to Review in OpenRewrite May 18, 2026
@Jenson3210
Jenson3210 merged commit 31d1416 into main May 18, 2026
@Jenson3210
Jenson3210 deleted the jenson3210/route-maven-through-moderne-cache branch May 18, 2026 13:49
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in OpenRewrite May 18, 2026
timtebeek added a commit to openrewrite/rewrite-java-dependencies that referenced this pull request May 18, 2026
openrewrite/gh-automation#95 installs ~/.m2/settings.xml with `<mirrorOf>*</mirrorOf>` to route Maven through `artifactory.moderne.ninja` and avoid HTTP 429 from Maven Central. The mirror rewrites every repository request — including the test pom's deliberately-unreachable `<repository><url>https://nonexistent.moderne.io/maven2</url></repository>` — so the diagnostic recipe only sees the mirror and the local file cache. Neither Maven Central nor the test repo appear in the data table, and both assertions fail.

Inject an explicit empty `MavenSettings` via `MavenExecutionContextView` (same pattern as `mavenSettingsWithMirrors`) so the recipe ignores `~/.m2/settings.xml` and sees the pom-declared repositories directly. The original three assertions are restored unchanged.
timtebeek added a commit to openrewrite/rewrite-java-dependencies that referenced this pull request May 18, 2026
…#178)

openrewrite/gh-automation#95 installs ~/.m2/settings.xml with `<mirrorOf>*</mirrorOf>` to route Maven through `artifactory.moderne.ninja` and avoid HTTP 429 from Maven Central. The mirror rewrites every repository request — including the test pom's deliberately-unreachable `<repository><url>https://nonexistent.moderne.io/maven2</url></repository>` — so the diagnostic recipe only sees the mirror and the local file cache. Neither Maven Central nor the test repo appear in the data table, and both assertions fail.

Inject an explicit empty `MavenSettings` via `MavenExecutionContextView` (same pattern as `mavenSettingsWithMirrors`) so the recipe ignores `~/.m2/settings.xml` and sees the pom-declared repositories directly. The original three assertions are restored unchanged.
sambsnyd pushed a commit to openrewrite/rewrite-java-dependencies that referenced this pull request Jul 14, 2026
…#178)

openrewrite/gh-automation#95 installs ~/.m2/settings.xml with `<mirrorOf>*</mirrorOf>` to route Maven through `artifactory.moderne.ninja` and avoid HTTP 429 from Maven Central. The mirror rewrites every repository request — including the test pom's deliberately-unreachable `<repository><url>https://nonexistent.moderne.io/maven2</url></repository>` — so the diagnostic recipe only sees the mirror and the local file cache. Neither Maven Central nor the test repo appear in the data table, and both assertions fail.

Inject an explicit empty `MavenSettings` via `MavenExecutionContextView` (same pattern as `mavenSettingsWithMirrors`) so the recipe ignores `~/.m2/settings.xml` and sees the pom-declared repositories directly. The original three assertions are restored unchanged.
sambsnyd added a commit to openrewrite/rewrite-java-dependencies that referenced this pull request Jul 14, 2026
… dependencies being reported on (#189)

* Include in Dependency Report the path to the build file declaring the dependencies being reported on

* OpenRewrite recipe best practices

Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.recipes.rewrite.OpenRewriteRecipeBestPractices?organizationId=QUxML01vZGVybmUvTW9kZXJuZSArIE9wZW5SZXdyaXRl

Co-authored-by: Moderne <team@moderne.io>

* Pin empty MavenSettings in DependencyResolutionDiagnosticTest.maven() (#178)

openrewrite/gh-automation#95 installs ~/.m2/settings.xml with `<mirrorOf>*</mirrorOf>` to route Maven through `artifactory.moderne.ninja` and avoid HTTP 429 from Maven Central. The mirror rewrites every repository request — including the test pom's deliberately-unreachable `<repository><url>https://nonexistent.moderne.io/maven2</url></repository>` — so the diagnostic recipe only sees the mirror and the local file cache. Neither Maven Central nor the test repo appear in the data table, and both assertions fail.

Inject an explicit empty `MavenSettings` via `MavenExecutionContextView` (same pattern as `mavenSettingsWithMirrors`) so the recipe ignores `~/.m2/settings.xml` and sees the pom-declared repositories directly. The original three assertions are restored unchanged.

* Speed up ModuleHasDependency and RepositoryHasDependency by removing DependencyInsight (#176)

* Speed up ModuleHasDependency and RepositoryHasDependency by removing DependencyInsight

Both recipes ran a fresh DependencyInsight visitor against every source file during
scanning, which performs exhaustive Gradle + Maven dependency analysis just to answer
a binary yes/no question about whether the module contains a given GAV.

Replace the visitor with a direct check against MavenResolutionResult.findDependencies
for Maven modules, and against GradleProject's configurations + ResolvedDependency.findDependency
for Gradle modules. This mirrors the pattern Sam applied to the single-build-system versions
of ModuleHasDependency in openrewrite/rewrite (commit 919c9f5 / PR #6664).

These recipes are used as preconditions in many declarative migration recipes.
Avoiding the DependencyInsight allocation + traversal per source file substantially
reduces scanner time on repositories with many Java files.

* Skip dependency scan in ModuleHasDependency once project is known to match

Avoids re-running the per-tree dependency lookup for every source file in a
module after the JavaProject has already been added to the accumulator.

---------

Co-authored-by: Tim te Beek <tim@moderne.io>

* Match requested dependencies in ModuleHasDependency and RepositoryHasDependency (#179)

* Regenerate recipes.csv (#180)

* Update Gradle wrapper 9.5.1

Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.gradle.UpdateGradleWrapper?organizationId=QUxML01vZGVybmUgKyBPcGVuUmV3cml0ZS9PcGVuUmV3cml0ZQ%3D%3D#defaults=W3sidmFsdWUiOiI5LjUuMSIsIm5hbWUiOiJ2ZXJzaW9uIn0seyJ2YWx1ZSI6ImJpbiIsIm5hbWUiOiJkaXN0cmlidXRpb24ifSx7InZhbHVlIjoiYmFmYzE0MWI2MTlhZDYzNTBmZDk3NWZjOTAzMTU2ZGQ1YzE1MTk5OGNjOGIwNThlOGMxMDQ0YWI1ZjdiMDMxZiIsIm5hbWUiOiJkaXN0cmlidXRpb25DaGVja3N1bSJ9XQ==

Co-authored-by: Moderne <team@moderne.io>

* Trust resolved version over declared dep in dependency search (#181)

* Trust resolved version over declared dep in dependency search

PR #179 extended ModuleHasDependency / RepositoryHasDependency to also
match against requested/declared dependencies so they still match when
resolution fails. This introduced false positives whenever a version
range is supplied: the declared version string could satisfy the
comparator even when the resolved version did not (e.g. a Gradle
resolutionStrategy.force or platform alignment overriding the declared
coordinate).

- When a coordinate is present in the resolved dependencies, trust the
  resolved check and skip the declared-dependency fallback for that
  group:artifact. Only fall back for declared deps not already resolved.
- Tighten versionMatches so a null declared version no longer
  auto-matches when a version constraint is supplied (same treatment as
  a ${...} property reference).

Adds regression tests covering both rules in ModuleHasDependencyTest and
RepositoryHasDependencyTest.

* Apply suggestions from code review

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>

* Add Maven regression tests for BOM-managed dependency version range

---------

Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>

* git-ignore .context/

Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.AddToGitignore?organizationId=QUxML01vZGVybmUgKyBPcGVuUmV3cml0ZQ%3D%3D#defaults=W3sidmFsdWUiOiIuY29udGV4dC8iLCJuYW1lIjoiZW50cmllcyJ9XQ==

Co-authored-by: Moderne <team@moderne.io>

* Fix RemoveDependency.unlessUsing for multi-module Maven projects (#183)

* Fix `RemoveDependency.unlessUsing` for multi-module Maven projects

`RemoveDependency` scans every source file and records whether `unlessUsing`
matched against the file's `JavaProject` marker. In a multi-module Maven
project the parent pom carries its own `JavaProject` distinct from the
children, so the parent module's accumulator entry never reflects type
usages found in child modules. The visitor would then strip the
`<dependency>` from the parent pom even though child modules in the same
reactor still relied on inheriting it.

Now the scanner additionally records the `MavenResolutionResult.id ->
JavaProject` mapping for every pom it visits. When the visitor is about to
remove a `<dependency>` from a pom, it walks that pom's descendant modules
via `MavenResolutionResult.getModules()` and preserves the declaration if
any descendant's `JavaProject` shows the type in use.

* Allow `RemoveDependency` to remove ancestor decl when descendants self-declare

The descendant-aware preservation introduced in the previous commit was
intentionally conservative: any descendant module whose Java sources used
the `unlessUsing` type blocked removal of the dep from an ancestor pom.
That over-preserves when a descendant module also declares the same
dependency directly in its own `<dependencies>` — in that case the
descendant is self-sufficient and the ancestor's declaration is dead
weight.

Refine the check: a descendant only blocks removal if it uses the type AND
does not declare the dependency itself. The self-declaration check looks
at the raw `requested` pom (as-written), not the resolved/inherited
dependency list, so a child that inherits the dep from the ancestor we
might modify still correctly blocks removal.

* Remove out-of-date OWASP suppressions

Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.xml.security.RemoveOwaspSuppressions?organizationId=QUxML01vZGVybmUgKyBPcGVuUmV3cml0ZQ%3D%3D#defaults=W3sidmFsdWUiOiIyMDI2LTA2LTE3IiwibmFtZSI6ImN1dE9mZkRhdGUifV0=

Co-authored-by: Moderne <team@moderne.io>

* Use GitHub actions/checkout@v7

Use this link to re-run the recipe: https://app.moderne.io/recipes/org.openrewrite.github.ChangeActionVersion?organizationId=QUxML01vZGVybmUgKyBPcGVuUmV3cml0ZQ%3D%3D#defaults=W3sidmFsdWUiOiJhY3Rpb25zL2NoZWNrb3V0IiwibmFtZSI6ImFjdGlvbiJ9LHsidmFsdWUiOiJ2NyIsIm5hbWUiOiJ2ZXJzaW9uIn1d

Co-authored-by: Moderne <team@moderne.io>

* Cache delegate recipes per recipe instance to avoid repeated construction (#184)

The Gradle/Maven dependency wrapper recipes (`AddDependency`, `ChangeDependency`, `UpgradeDependencyVersion`, `UpgradeTransitiveDependencyVersion`) each delegate to a Gradle and a Maven `ScanningRecipe`. Previously a fresh delegate instance was constructed on every `getInitialValue`/`getScanner`/`getVisitor`/`validate` call (and, in `AddDependency`, once per source file inside the scanner's `visit`).

Each `ScanningRecipe` construction runs `UUID.randomUUID()` for its accumulator-message key, which draws from `SecureRandom` and dominated profiles of recipe-heavy runs.

Memoize each delegate lazily on the wrapper recipe instance (a `final transient AtomicReference` that is excluded from the generated constructor and from `equals`/`hashCode`) so it is built at most once per wrapper instance and reused across the scanning and editing phases. The delegate is derived from the wrapper's options, so it belongs to the recipe instance rather than the accumulator: callers such as `rewrite-spring` deliberately reuse a single accumulator across two wrapper instances that have different options, so caching the delegate on the accumulator would reuse the wrong options.

The `Accumulator` types are left unchanged, preserving their public constructors for downstream callers that build them directly.

* Add software.amazon.ion:ion-java -> com.amazon.ion:ion-java relocation (stopgap) (#185)

* [Auto] Old GroupId migrations as of 2026-06-23T1723

* Update findRelocatedIonJava test for new relocation context (#186)

The [Auto] Old GroupId migrations update (5253cf5) added a context note
to the software.amazon.ion:ion-java relocation in migrations.csv. The
RelocatedDependencyCheck recipe now surfaces that context both in the
RelocatedDependencyReport data table row and in the inline search-result
marker comment, so update the test expectations to match.

Fixes the scheduled CI failure in run 28122079598.

* Keep direct dependencies whose scope or exclusions differ from the transitive one (#188)

* Keep direct dependencies whose scope or exclusions differ from the transitive one

RemoveRedundantDependencies removed a direct dependency whenever a matched
parent provided the same coordinate transitively, ignoring scope and
exclusions. This silently changed the effective classpath when the direct
declaration carried information the transitive entry did not.

A direct dependency is now only removed when the transitive one provides it
at the exact same effective scope and with the same exclusions:

- Track each transitive dependency's effective exclusions and only treat a
  direct dependency as redundant when its exclusions match exactly.
- Key Maven transitives by the parent dependency's own effective scope and
  compare against the direct dependency's effective scope, rather than
  treating a broader transitive scope as covering a narrower direct one.

Fixes the five scenarios from openrewrite/rewrite#8235.

* Simplify test POMs: drop XML declaration and project attributes

* Extract handleGradle/handleMaven and trim comments

* Rename getCompatibleTransitives to getCompatibleGradleTransitives

* Polish

---------

Co-authored-by: Tim te Beek <timtebeek@gmail.com>
Co-authored-by: Moderne <team@moderne.io>
Co-authored-by: Tim te Beek <tim@moderne.io>
Co-authored-by: Steve Elliott <steve@moderne.io>
Co-authored-by: Jente Sondervorst <jentesondervorst@gmail.com>
Co-authored-by: Greg Oledzki <greg.oledzki@moderne.io>
Co-authored-by: Knut Wannheden <knut@moderne.io>
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