Proposal: Add modify_classpath to JavaInfo
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- java
- 领域
- build-system
调研方向
首先审查公开 modify_classpath 的模块文件补丁,并将其与当前 JavaInfo 和 java_common.merge 的行为进行比较。明确排除 jar 以及添加编译时或运行时 jar 应如何影响返回的 JavaInfo,然后在将其投入生产并创建 pull request 之前验证该设计。
由索引模型根据 Issue 内容生成。
描述
Context
We maintain a large Monorepo for multiple JVM languages that allows for multiple versions of external dependencies.
When JavaInfo objects are merged, the version that ends up on the classpath depends on the order that dependencies were declared in the 'deps' field (and other similar fields, such as exports and runtime_deps).
This can lead to situations where a target may depend directly on MyLibrary-1.0, but a different dependency appearing earlier in 'deps' transitively bring in MyLibrary-2.0. The version resolved on the classpath will be MyLibrary-2.0, despite the desired version being MyLibrary-1.0.
Proposal
Our module file adds a patch file that exposes a new method in JavaInfo called 'modify_classpath'. The method accepts a JavaInfo object and constructs a new JavaInfo object with selected jars pruned from the classpath. This is the method header:
def modify_classpath(java_info, exclude_jars = [], add_compile_jars = [], add_runtime_jars = []):
"""Returns a copy of the given JavaInfo with modified compile and runtime classpaths.
Enables classpath manipulation: excluding specific jars and/or adding new jars to the compile-time
and runtime classpaths.
Args:
java_info: (JavaInfo) The JavaInfo to modify.
exclude_jars: ([File]) Jars to remove from all classpath fields.
add_compile_jars: ([File]) Jars to prepend to the compile-time classpath.
add_runtime_jars: ([File]) Jars to prepend to the runtime classpath.
Returns:
(JavaInfo) A new JavaInfo with the modified classpaths.
Our call flow is essentially:
dep_java_infos = [dep[JavaInfo] for dep in ctx.attr.deps if JavaInfo in dep]
merged_java_info = java_common.merge(dep_java_infos)
pruned_java_info = java_common.modify_classpath(merged_java_info, exclude_jars = exclude_jars)
This enables selective exclusion of MyLibrary-2.0 from the merged JavaInfo object, allowing MyLibrary-1.0 to be resolved on the classpath
We have a working proof of concept. We would appreciate high-level feedback before productionizing and creating the PR.
Thank you!
- 主要语言
- Starlark
- 星标
- 103
- 派生
- 102
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazelbuild/rules_java 的其他 Issue
-
P4
难度 4/5 3-5 天 新手友好度 55/100
bazelbuild/rules_java#360 · 4 条评论 · 2 个 reaction ·
-
P3 question
难度 3/5 1-2 天 新手友好度 45/100
bazelbuild/rules_java#339 · 1 条评论 ·
-
P3
难度 4/5 3-5 天 新手友好度 35/100
bazelbuild/rules_java#325 · 8 条评论 ·
-
P4
难度 4/5 3-5 天 新手友好度 35/100
bazelbuild/rules_java#316 · 2 个 reaction ·
-
P2
难度 4/5 3-5 天 新手友好度 35/100
bazelbuild/rules_java#289 · 1 条评论 ·
查看 bazelbuild/rules_java 的全部 Issue
相似的 Issue
-
type/automation type/tech-debt
难度 2/5 1-3 小时 新手友好度 78/100
-
priority: p3
难度 2/5 1-3 小时 新手友好度 72/100
googleapis/librarian#7636 ·
-
package-update
难度 2/5 1-3 小时 新手友好度 72/100
oSoWoSo/vOid_Community_repOsitory#147 · 1 条评论 ·
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
-
agentic-workflows cascade-suspected
难度 1/5 1 小时以内 新手友好度 88/100