Proposal: Add modify_classpath to JavaInfo

Abierto
#354 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
java
Área
build-system

Línea de trabajo

Comienza revisando el parche del archivo de módulo que expone modify_classpath y compáralo con el comportamiento actual de JavaInfo y java_common.merge. Define cómo deberían afectar al JavaInfo devuelto la exclusión de jars y la adición de jars en tiempo de compilación o de ejecución; después, valida el diseño antes de prepararlo para producción y crear un pull request.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

P4

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!

Lenguaje dominante
Starlark
Estrellas
103
Forks
102
Métricas de merge de PR
Sin PR fusionados en 30 d

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bazelbuild/rules_java

Todos los issues de bazelbuild/rules_java

Issues similares

Más issues de Build System

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.