bazelbuild / bazelbuild/bazel

deploy jar silently clobbers jar resources having the same filename

Open
#7,330 16 comments 3 reactions 0 assignees View on GitHub
not stale P3 team-Rules-Java type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

When creating a deploy jar (`bazel build foo_deploy.jar`), if multiple constituent jars have resource files with identical names, only one appears in the deploy jar. This can catch users off guard, as their build succeeded but the bits will fail at runtime.

This is likely to happen when porting a project from Maven to Bazel, where the Maven deployment consists of individually deployed jars, and the developer is experimenting with Bazel's monolithic deploy jar.

Bazel ought to at least emit a warning when one file clobbers another while assembling a deploy jar, if it doesn't terminate the build altogether.

### Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

```bash
#!/bin/bash

set -e

## Create project
# WORKSPACE and top-level java_binary
touch WORKSPACE
cat > BUILD < src/main/java/resource_demo.java < ${proj}/src/main/resources/id.dat
cat > $proj/BUILD <

Contributor guide

Open the contributing guide

Research direction

Start with Singlejar.java and DeployArchiveBuilder.java, then run the supplied reproduction to observe duplicate resource handling in a deploy JAR. Check how --warn_duplicate_resources is used for source JARs and determine whether deploy JAR creation should pass it through. Done means duplicate resource names produce a warning or otherwise visible build diagnostic instead of silently clobbering one resource.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.