Keywords: Maven | Java Modularization | Compilation Error | ASM Library | maven-compiler-plugin
Abstract: This technical article provides an in-depth analysis of IllegalArgumentException errors encountered when compiling module-info.java files in Maven projects targeting Java 10 and 11. The root cause is identified as version incompatibility between maven-compiler-plugin 3.7.0 and newer Java versions. Two practical solutions are presented: upgrading to maven-compiler-plugin 3.8.0 or manually specifying updated ASM dependencies, supported by code examples and architectural insights into module system integration with build tools.
Problem Background and Error Analysis
With the introduction of the module system in Java 9, developers need to include module-info.java files to define module boundaries. However, when using Maven as the build tool, particularly for Java 10 and 11 projects, compilation failures frequently occur. The stack trace reveals that the issue originates in the org.objectweb.asm.ClassReader constructor, indicating compatibility problems between the Maven compiler plugin and the ASM library when processing module descriptors.
Root Cause Investigation
The maven-compiler-plugin version 3.7.0 relies on an outdated version of the ASM library that cannot properly handle new bytecode features introduced in Java 10 and 11. When the plugin attempts to parse module-info.java files, the ASM library fails to recognize the updated class file format, resulting in IllegalArgumentException exceptions. This problem is particularly evident during the test compilation phase (testCompile), as Maven handles module path resolution for both main and test code simultaneously.
Solution 1: Upgrade Compiler Plugin Version
The most straightforward and effective solution is to upgrade maven-compiler-plugin to version 3.8.0 or higher. The updated plugin includes compatible ASM dependencies that fully support modularization features from Java 9 onward. Configuration example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
Using the <release> parameter instead of traditional <source> and <target> settings ensures the compiler utilizes the complete feature set of the specified Java version while avoiding platform-specific API compatibility issues. Note that starting from version 3.8.0, the default source and target versions have been elevated from 1.5 to 1.6.
Solution 2: Manual ASM Dependency Update
If plugin version upgrade is constrained by project requirements, explicitly specifying a newer ASM dependency within the existing plugin configuration provides an alternative approach:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>10</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
</plugin>
This method leverages dependency overriding to force the plugin to use ASM versions compatible with Java 10/11. Developers can search Maven Central Repository for the latest ASM versions suitable for replacement.
Related Technical Extensions
Similar issues have emerged in other Java ecosystem tools. The referenced article mentions that Lombok's @Builder annotation also causes compilation errors in Java 10/11 environments, further demonstrating the compatibility requirements that new Java versions impose on bytecode processing libraries. The module system has fundamentally changed Java application architecture, requiring corresponding updates in build tools and code generation utilities.
Best Practice Recommendations
For new projects, directly using the latest stable version of maven-compiler-plugin with <release> parameter configuration is recommended. When upgrading existing projects, comprehensive build process testing is essential to ensure all dependencies remain compatible with the target Java version. Regularly updating the build toolchain helps prevent similar compatibility issues and improves development efficiency.