Skip to content

[java] put third-party jars under lib/ in dist zips again by matching prefixes on canonical labels - #18165

Merged
titusfortner merged 1 commit into
SeleniumHQ:trunkfrom
titusfortner:java-dist-zip-lib
Oct 13, 2026
Merged

titusfortner merged 1 commit into
SeleniumHQ:trunkfrom
titusfortner:java-dist-zip-lib

Conversation

@titusfortner

Copy link
Copy Markdown
Member

🔗 Related Issues

Regressed from #13726 (released with Selenium 4.20)

💥 What does this PR do?

Restores the pre-4.20 layout of the selenium-java and selenium-server zips: Selenium jars and their sources at the root, third-party jars under lib/ without their sources.

🔧 Implementation Notes

  • Root cause: third_party_prefixes were matched against str(label), which under Bzlmod is @@rules_jvm_external++maven+maven//... for Maven deps and @@//... for this repo, so neither @maven// nor //third_party ever matched.
  • Prefixes are now resolved with Label() and compared on repo name and package, so apparent names like @maven map to their canonical repos.
  • Restores lib/ rather than making the flat layout official; a -cp "dir/*" classpath now misses the third-party jars, while -cp "dir/*:dir/lib/*" works with either layout.
  • Dropping the third-party -sources.jar files shrinks the selenium-java zip from 38 to 34 MB and the selenium-server zip from 135 to 110 MB.

🤖 AI assistance

  • AI assisted (complete below)
    • Tool(s): Claude Code (Opus 5.5)
    • What was generated: diagnosis, fix, release zip layout comparison, and this description
    • I reviewed all AI output and can explain the change

🔄 Types of changes

  • Bug fix

@selenium-ci selenium-ci added C-java Java Bindings B-build Includes scripting, bazel and CI integrations labels Oct 13, 2026
@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Restore third-party jars to lib/ in Java distribution zips

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Restore third-party jars to lib/ in selenium-java and selenium-server zips after a Bzlmod
 regression.
• Keep Selenium jars and sources at the root while excluding third-party source jars.
Diagram

graph TD
  A["Dist aspect"] --> C["Party classifier"] --> D["Zip assembly"]
  B["Resolved prefixes"] --> C
Loading
High-Level Assessment

Keep the Label-based comparison: it resolves apparent repository names under Bzlmod without changing the existing zip assembly rules. Matching or rewriting label strings would retain the source of the regression.

Files changed (1) +5 / -4

Bug fix (1) +5 / -4
dist_info.bzlClassify distribution jars using resolved labels +5/-4

Classify distribution jars using resolved labels

• DistInfo now stores the target Label rather than its string representation. Third-party prefixes are resolved to Labels and matched by repository name and package prefix, restoring the existing lib/ placement and third-party source exclusion.

java/private/dist_info.bzl

@qodo-code-review

qodo-code-review Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 📜 Skill insights (0)

Grey Divider


Action required

1. Flat classpaths miss dependencies ✗ Dismissed
Description
separate_first_and_third_party now recognizes canonical Maven and repository labels, causing
matching dependencies to be emitted through the third-party path. When users use -cp "dir/*",
those jars are written under lib/ and are not loaded, breaking applications that relied on the
flat zip layout.
Code

java/private/dist_info.bzl[R91-101]

+def _is_third_party(prefixes, label):
    for prefix in prefixes:
-        if target.startswith(prefix):
+        if label.repo_name == prefix.repo_name and label.package.startswith(prefix.package):
            return True
    return False

def separate_first_and_third_party(third_party_prefixes, dist_zip_infos):
+    prefixes = [Label(prefix + ":__pkg__") for prefix in third_party_prefixes]
    combined = depset(transitive = [i.dist_infos for i in dist_zip_infos])

    first_party = []
Evidence
The changed classifier converts apparent prefixes into canonical labels and now classifies matching
dependencies as third-party. The zip rule places every classified third-party binary under lib/,
so the restored layout changes the classpath behavior for consumers using only the zip root.

AGENTS.md: Preserve Public API and ABI Compatibility and Deprecate Before Removal
java/private/dist_info.bzl[91-107]
java/private/dist_zip.bzl[20-24]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The canonical-label matching changes the zip layout so third-party jars move under `lib/`, which breaks consumers that load dependencies with `-cp "dir/*"`.

## Fix Focus Areas
- java/private/dist_info.bzl[91-107]
- java/private/dist_zip.bzl[20-24]

## Recommended Fix
Preserve compatibility for existing consumers by keeping third-party jars available to the flat classpath, or provide an equivalent compatibility mechanism and clearly migrate users to the `dir/lib/*` classpath before removing the old behavior.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Zip layout changes lack focused tests 📘 Rule violation ≡ Correctness
Description
separate_first_and_third_party adds canonical Label() resolution and repository/package prefix
matching without a focused test for the resulting classification. A malformed prefix or
canonical-repository mismatch can therefore place Selenium or third-party jars in the wrong archive
location without an automated check of the generated zip contents.
Code

java/private/dist_info.bzl[R91-98]

+def _is_third_party(prefixes, label):
    for prefix in prefixes:
-        if target.startswith(prefix):
+        if label.repo_name == prefix.repo_name and label.package.startswith(prefix.package):
            return True
    return False

def separate_first_and_third_party(third_party_prefixes, dist_zip_infos):
+    prefixes = [Label(prefix + ":__pkg__") for prefix in third_party_prefixes]
Evidence
The PR changes the classification algorithm and prefix parsing, while repository searches found no
focused test covering separate_first_and_third_party or the generated zip layout. The affected
logic directly determines whether each dependency is emitted at the root or under lib/.

AGENTS.md: Use Focused Tests That Exercise Real API Contracts
java/private/dist_info.bzl[91-107]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new canonical-label matching logic changes which jars are placed at the archive root versus under `lib/`, but the repository has no focused test covering this behavior.

## Fix Focus Areas
- java/private/dist_info.bzl[91-107]

## Recommended Fix
Add a focused Bazel test or fixture that exercises apparent Maven and repository prefixes against canonical labels, verifies first-party and third-party classification, and checks that generated distribution zips contain binaries and sources in the expected locations.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Dismiss ↗ | View ↗


Grey Divider

Context sources
Review mode: Auto: ⚖️ Balanced: Packaging behavior and canonical-label matching warrant careful review.

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display > Comment parts

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread java/private/dist_info.bzl
Comment thread java/private/dist_info.bzl
@titusfortner
titusfortner merged commit af64b13 into SeleniumHQ:trunk Oct 13, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

B-build Includes scripting, bazel and CI integrations C-java Java Bindings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo