apache / apache/maven-compiler-plugin

[MCOMPILER-462] Modular Multi-Release JAR and Maven-Bundle-Plugin together cause inconsistent compilation behavior

Open
#680 0 comments 0 reactions 0 assignees View on GitHub
bug priority:major
Dominant language
Java
Stars
261
Forks
191
Avg merge
1d 5h
Merged PRs (30d)
8

Description

**[Anand Beh](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=a248)** opened **[MCOMPILER-462](https://issues.apache.org/jira/browse/MCOMPILER-462?redirect=false)** and commented

Building a project with a module descriptor placed in a multi-release directory, and in conjunction with the maven-bundle-plugin, creates discrepancies between "clean package" and "package" after changes have been made to the source tree.

This is best explained by reproducing the issue.

**Reproducer**

Attached to this issue. Also clonable from https://github.com/A248/ModularMRJAR

**Steps to reproduce**
1. Download the attached reproducer
2. **First Run:** Run _mvn package_
3. Add a new class, e.g. "Clazz2" in src/main/java/org/mrjar
4. **Second Run**: Run _mvn package_
5. **Third Run**: Run _mvn clean package_

The Second Run can be repeated any number of times. It will consistently fail with the reason that the org.mrjar package is not found.

**Results**

 
* First Run - compilation success
* Second Run - failure
* Third Run - success

The Third Run and the Second Run should compile identically.

**Analysis**

The difference between the second run and the third run is visible using the -X option.

The trouble happens when compiling the MR classes - i.e., the compile-java11 execution defined in the reproducer's pom.

On the second run, the non-MR classes are placed on the modulepath. The MR classes fail to compile:

```java
[DEBUG] Classpath:
[DEBUG] Modulepath:
[DEBUG] /Users/anandbeh/git/ModularMRJAR/target/classes
[DEBUG] Source roots:
[DEBUG] /Users/anandbeh/git/ModularMRJAR/src/main/java11
[DEBUG] Command line options:
[DEBUG] -d /Users/anandbeh/git/ModularMRJAR/target/classes/META-INF/versions/11 --module-path /Users/anandbeh/git/ModularMRJAR/target/classes: -sourcepath /Users/anandbeh/git/ModularMRJAR/src/main/java11:/Users/anandbeh/git/ModularMRJAR/target/generated-sources/annotations: -s /Users/anandbeh/git/ModularMRJAR/target/generated-sources/annotations -g -nowarn --release 11 -encoding UTF-8 --module-version 0.1.0-SNAPSHOT
```

On the third run, the non-MR classes are placed on the classpath. The MR classes compile. It is further notable that the compiler command line options differ:

 

```java
[DEBUG] Classpath:
[DEBUG] /Users/anandbeh/git/ModularMRJAR/target/classes
[DEBUG] Source roots:
[DEBUG] /Users/anandbeh/git/ModularMRJAR/src/main/java11
[DEBUG] Command line options:
[DEBUG] -d /Users/anandbeh/git/ModularMRJAR/target/classes/META-INF/versions/11 -classpath /Users/anandbeh/git/ModularMRJAR/target/classes: -sourcepath /Users/anandbeh/git/ModularMRJAR/src/main/java11:/Users/anandbeh/git/ModularMRJAR/target/generated-sources/annotations: -s /Users/anandbeh/git/ModularMRJAR/target/generated-sources/annotations -g -nowarn --release 11 -encoding UTF-8 --patch-module org.mrjar=/Users/anandbeh/git/ModularMRJAR/target/classes --module-version 0.1.0-SNAPSHOT
```

 
**How to Resolve / Lesson from when not using the maven-bundle-plugin**

If the maven-bundle-plugin were to _NOT_ be used, then:
1. The Second Run would succeed.
2. The non-MR classes are placed on the class-path consistently.

This suggests the behavior of the Second Run in placing the non-MR classes on the module-path is incorrect. The Second Run should place the non-MR classes on the class-path just like the Third Run does.

---

**Affects:** 3.8.1

**Attachments:**
- [ModularMRJAR.zip](https://issues.apache.org/jira/secure/attachment/13024416/ModularMRJAR.zip) (_41.89 kB_)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.