apache / apache/maven-jar-plugin

Race condition when two Jars being created at the same time

Open
#144 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
92
Forks
84
Avg merge
19h 45m
Merged PRs (30d)
6

Description

### Affected version

3.4.2

### Bug description

Sorry if am sending this bug report to the wrong place. While there are MJAR tickets in Jira, I couldn't create a ticket against that project, so sending it here.

We have been dealing with an intermittent problem where occasionally one of the jar files in our build would be non-functional. It turned out that the file was < 10KB, only containing the immediate project output, wtih no dependencies included.

It appears that this could be an issue with the maven JAR plugin when maven is run with -T 3

An example of the JAR file being correctly build looks like this:
09:00:55 [INFO] --- maven-jar-plugin:3.4.2:jar (default-jar) @ maestro-ocelot-log-level-lambda ---
09:00:55 [INFO] Building jar: /var/build/workspace/build-maestro/maestro-ocelot-log-level-lambda/target/maestro-ocelot-log-level-lambda.jar
09:00:55 [INFO]
09:00:55 [INFO] --- maven-shade-plugin:3.6.0:shade (default) @ maestro-ocelot-log-level-lambda ---
09:00:55 [INFO]
09:00:55 [INFO] -------------------------------------------------------
09:00:55 [INFO] T E S T S
09:00:55 [INFO] -------------------------------------------------------
09:00:55 [INFO] Including com.amazonaws:aws-lambda-java-core:jar:1.2.3 in the shaded jar.

followed by lots of shade output and a functional zip file of ~ 55 MBs.

An example of a build that results in a JAR file missing dependences looks like this:

0:35:26 [INFO] --- maven-jar-plugin:3.4.2:jar (default-jar) @ maestro-ocelot-log-level-lambda ---
10:35:26 [INFO] Building jar: /var/build/workspace/build-maestro/maestro-ocelot-log-level-lambda/target/maestro-ocelot-log-level-lambda.jar
10:35:26 [INFO] Building jar: /var/build/workspace/build-maestro/maestro-contracts/target/maestro-contracts-0.0.1.3455-tests.jar
10:35:26 [INFO]
10:35:26 [INFO] --- maven-shade-plugin:3.6.0:shade (default) @ maestro-ocelot-log-level-lambda ---
10:35:26 [INFO]
10:35:26 [INFO] --- maven-install-plugin:3.1.4:install-file (default) @ maestro-contracts ---
10:35:26 [INFO] No artifact matching filter net.logstash.logback:logstash-logback-encoder
10:35:26 [INFO] No artifact matching filter com.inin.messages:inin-messages-events
10:35:26 [INFO] Replacing original artifact with shaded artifact.
10:35:26 [INFO] Replacing /var/build/workspace/build-maestro/maestro-ocelot-log-level-lambda/target/maestro-ocelot-log-level-lambda.jar with /var/build/workspace/build-maestro/maestro-ocelot-log-level-lambda/target/maestro-ocelot-log-level-lambda-0.0.1.3455-shaded.jar

Notice that the shade plugin did not do any work, which I assume means that the JAR file didn't have any dependencies for it to clean up. The JAR file ended up being < 10 KBs.

I found three examples of this issue. Every time that the zip file did not contain any dependencies the log file showed that 2 JAR files were being generated at the same time.

Does this give enough to go on or would there be any tracing that I could enable to help troubleshoot this issue?

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the reported build with Maven running at -T 3, focusing on the maven-jar-plugin and maven-shade-plugin log sequence. Compare successful and failing builds where two JAR files are generated at the same time; done means the shaded artifact consistently contains its dependencies rather than producing an incomplete JAR.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.