bazelbuild / bazelbuild/rules_java
Proposal: Add modify_classpath to JavaInfo
- Ngôn ngữ chính
- Starlark
- Star
- 103
- Fork
- 102
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
## 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!
Hướng dẫn đóng góp
Hướng nghiên cứu
Bắt đầu bằng cách xem xét bản vá của tệp module expose modify_classpath và so sánh nó với hành vi hiện tại của JavaInfo và java_common.merge. Xác định việc loại trừ các jar và thêm các jar khi biên dịch hoặc khi chạy sẽ ảnh hưởng như thế nào đến JavaInfo được trả về, sau đó xác thực thiết kế trước khi hoàn thiện cho môi trường production và tạo một pull request.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- java
- Lĩnh vực
- build-system
- Loại issue
- Tính năng
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức độ hoạt động
- Ít trao đổi
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100