maven-compiler-plugin icon indicating copy to clipboard operation
maven-compiler-plugin copied to clipboard

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

Open jira-importer opened this issue 4 years ago • 0 comments

Anand Beh opened MCOMPILER-462 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:

[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:

 

[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:

jira-importer avatar Apr 22 '21 02:04 jira-importer