Skip to content

fix(maven,gradle): look artifacts up on Maven Central only when no build file names another repository - #173

Merged
sweepies merged 6 commits into
mainfrom
feat/maven-gradle-origins
Nov 4, 2026
Merged

sweepies merged 6 commits into
mainfrom
feat/maven-gradle-origins

Conversation

@sweepies

@sweepies sweepies commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fourth per-ecosystem fix from the registry audit, after Bundler (#168), Composer (#170) and NuGet (#171). Maven and Gradle looked every artifact up on Maven Central (or Google's repository for Android groups), so an artifact from a private repository could be looked up there.

Why the rule is coarse

Neither Maven nor Gradle records which repository served an artifact: no lockfile has it, and Gradle's lockfile and verification metadata hold versions and checksums only. Both try repositories in order and take the first hit, and Gradle adds content filters on top. Following that would mean re-implementing their resolution. So the Count over-counts: any repository besides Maven Central, Google's and the Gradle Plugin Portal anywhere in the build fails every lookup of that build system. Private Maven repositories aren't read yet anyway, as for the other ecosystems.

For comparison, Renovate merges the version lists of every repository it finds, which is the dependency-confusion pattern this avoids. It also drops repositories it can't parse.

Maven

  • Every pom.xml: repository, pluginRepository and snapshotRepository, in any profile. Ones under distributionManagement don't count, since that's where a project deploys, not where it resolves from.
  • Every file named *settings.xml whose root is <settings>: mirrors and repositories.
  • .mvn/maven.config naming -s/-gs settings the Count doesn't read fails.
  • A URL with a property such as ${repo.url}, or a POM the Count can't parse or read, fails.

Gradle

  • Files read: every script, the sources in buildSrc, build-logic, build-conventions and gradle/plugins, and the sources of every build the settings include.
  • Lexer: comments and the literal text of strings are blanked. Code inside ${ … } templates stays code, and Groovy slashy and dollar-slashy strings are handled. Kafka's real build needed both.
  • Allowed: mavenCentral(), google(), gradlePluginPortal() and jcenter().
  • Fails every lookup:
    • maven, ivy, flatDir, mavenLocal, exclusiveContent, or anything mentioning ArtifactRepository/RepositoryHandler, outside a publishing { } block;
    • apply from a URL;
    • an includeBuild whose folder has no files;
    • build logic that won't lex or whose braces don't balance.
  • Engine, two passes: included builds can live anywhere, so the engine reads their sources in a second pass after the settings are read, on both the GitHub and working-tree paths. A symlinked or non-text source there counts as unreadable.

Tests

  • Unit tests: Maven and Gradle cases for each rule, including a credential in a repository URL never reaching a report.
  • Engine: a test for the second pass.
  • Corpus: the real Kafka and Spring PetClinic builds read as public. Kafka's included api-checker build isn't in the corpus, so the Kafka check allows that one reason.

Docs: sources.md (package registries), compatibility.md, and departures.md (new #maven-repositories).

View guided diff Turn on auto-fix

Policy: visible evidence

Decided with the maintainer. Lookups fail when committed build files show another repository. Repositories added only by Gradle plugins (e.g. JFrog Artifactory), Maven build extensions, init scripts or a CI machine's own settings aren't in the repository's files, so the Count doesn't see them. Maven Central and the Gradle Plugin Portal verify namespace ownership, which keeps someone else from publishing a private group's coordinates there. A private coordinate's name can still reach Central in a lookup.

Follow-ups

  • Repositories in remote parent POMs or imported BOMs aren't read.

  • mavenCentral { url = … } or mavenCentral().setUrl(…), which retarget a public repository, aren't detected.

  • An included build's sources are fetched one blob per file on the GitHub path, which is costly for a large included build.

  • Regex extractors with source = maven skip this check, as for the other ecosystems.

  • Further ways Gradle build logic can name a repository that the scan does not recognise, e.g. multi-line apply calls or repositories named through variables in plugin code. Under the visible-evidence policy these are accepted as unseen.

…ild file names another repository

Maven and Gradle looked every artifact up on Maven Central (or Google's
repository for Android groups), so an artifact from a private repository
could be looked up there. Neither tool records which repository served
an artifact, and both try repositories in order, so the Count does not
work out which one an artifact comes from: any repository other than
Central, Google's and the Gradle Plugin Portal anywhere in the build
fails every lookup of that build system.

- Maven: every pom.xml (any profile, not distributionManagement), every
  *settings.xml in the repository (mirrors and repositories) and
  .mvn/maven.config naming settings the Count does not read.
- Gradle: every script, the sources of buildSrc and other build-logic
  folders, and of every build the settings include, read with a lexer
  that keeps template code as code and knows slashy strings. maven, ivy,
  flatDir, mavenLocal, exclusiveContent, custom ArtifactRepository use or
  apply from a URL outside a publishing block, and build logic the Count
  cannot read, fail every lookup.
- The engine reads included builds' sources in a second pass, since only
  the settings say where they are; a symlinked or non-text one there is
  unreadable.
@deepsource-io

deepsource-io Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 00a6c99...0fb8ff1 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Nov 4, 2026 2:55a.m. Review ↗
JavaScript Nov 4, 2026 2:55a.m. Review ↗
Shell Nov 4, 2026 2:55a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 3119f43 Commit Preview URL

Branch Preview URL
Nov 04 2026, 02:32 AM

Comment thread crates/manager/src/gradle.rs Outdated
Comment on lines +677 to +679
let end = (i..bytes.len())
.find(|&j| !word(bytes[j]))
.unwrap_or(bytes.len());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use of `unwrap_or` followed by function call, prefer `unwrap_or_else` instead


Calls to unwrap_or followed by a function call should be replaced with
unwrap_or_else or unwrap_or_default, to increase laziness. The argument to
unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or
unwrap_or_default are evaluated lazily and only if required, sometimes
leading to lower overhead and fewer allocations.

@context7

context7 Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Docs7 for sweepies/count-patchula

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 0fb8ff1

…ed builds

From review of the first version:

- Maven: POMs a module or a parent's relativePath names, and settings or
  a POM .mvn/maven.config names (-s, -gs, -f in every form commons-cli
  takes), are fetched and scanned; a required one that is missing fails.
  A *settings.xml that looks like Maven's but does not parse fails rather
  than being skipped.
- Gradle: build logic is read as a worklist from the scripts and
  build-logic folders through every build included and script applied.
  apply from takes a plain string, file(...), rootProject.file(...), or
  a path under $rootDir or $projectDir; anything else, and includeBuild
  outside a settings script or with a computed name, fails. Kotlin raw
  strings take no escapes, backtick names (`maven-publish`) are names,
  and templates mark a string as computed.
- A symlinked .mvn or build-logic folder is unreadable.
- The engine reads what the files name until they name nothing new.
Comment thread crates/manager/src/gradle.rs Outdated
Comment on lines +448 to +450
let between: String = code[end..*start]
.chars()
.filter(|c| !c.is_whitespace())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Called `.chars().filter(..)` when `.matches(..)` would suffice


Using .chars().filter(..) requires additional logic and complexity compared to using .matches(..)
Using matches(..) allows for much greater flexibility such as using Pattern trait bound types,
and matching string expressions directly.

- Gradle scripts anywhere are build logic, except fixtures in a source
  set's test or resource folder, so a project under a folder named src is
  read.
- A backticked plain name (`maven`) stays code; a quoted repository call
  ('maven' { … }) fails; Java sources take no templates or slashy strings.
- An apply that names from any other way (apply(mapOf("from" to …)),
  apply to: p, from: …) fails. A plain apply-from path resolves against
  the project's folder, and $rootDir in buildSrc is buildSrc.
- Maven: a module or parent named without .xml can be a file or a folder;
  text split by comments is read whole; flags run together before -s, -gs
  or -f are read; Maven 4 subprojects are followed.
- No panic on a non-ASCII character before from.
- A source set is a test fixture by its name (test, testFixtures,
  functionalTest), not by containing "test" (latest, contest).
- buildSrc's own scripts use buildSrc as $rootDir; its plugins run in
  the main build and use the main root.
- A .apply { … } on an object, or a method named apply, is not Gradle's
  apply.
- Maven: only repository, pluginRepository and mirror elements in their
  lists count, not a plugin setting named repository.
@sweepies
sweepies merged commit b87af2d into main Nov 4, 2026
15 checks passed
@sweepies
sweepies deleted the feat/maven-gradle-origins branch November 4, 2026 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant