Skip to content

Commit aa49776

Browse files
committed
move module-info.java out of the java directory to avoid problems in eclipse
1 parent 708085c commit aa49776

3 files changed

Lines changed: 50 additions & 0 deletions

File tree

pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
<!-- plugins -->
3939
<central-publishing-plugin.version>0.10.0</central-publishing-plugin.version>
40+
<build-helper-plugin.version>3.6.1</build-helper-plugin.version>
4041
<checkstyle-plugin.version>3.6.0</checkstyle-plugin.version>
4142
<pmd-plugin.version>3.28.0</pmd-plugin.version>
4243
<spotbugs-plugin.version>4.9.8.2</spotbugs-plugin.version>
@@ -72,6 +73,26 @@
7273

7374
<build>
7475
<plugins>
76+
<plugin>
77+
<groupId>org.codehaus.mojo</groupId>
78+
<artifactId>build-helper-maven-plugin</artifactId>
79+
<version>${build-helper-plugin.version}</version>
80+
<executions>
81+
<execution>
82+
<id>add-module-source</id>
83+
<phase>generate-sources</phase>
84+
<goals>
85+
<goal>add-source</goal>
86+
</goals>
87+
<configuration>
88+
<sources>
89+
<source>src/main/module-info</source>
90+
</sources>
91+
</configuration>
92+
</execution>
93+
</executions>
94+
</plugin>
95+
7596
<plugin>
7697
<artifactId>maven-compiler-plugin</artifactId>
7798
<version>${compiler-plugin.version}</version>

src/main/module-info/readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Module Info Directory
2+
3+
This directory contains the `module-info.java` file for the Java Platform Module System (JPMS).
4+
5+
## Why is this in a separate directory?
6+
7+
The `module-info.java` file is kept separate from `src/main/java/` for the following reasons:
8+
9+
1. **Eclipse IDE Compatibility**: Eclipse has known issues with Java modules, particularly when the project uses older Java versions or has complex module configurations. Keeping `module-info.java` separate prevents Eclipse from attempting to process it during development.
10+
11+
2. **Build-Time Integration**: The module descriptor is added to the compilation during the Maven build process via the `build-helper-maven-plugin`, which adds this directory as a source folder only during the build.
12+
13+
3. **IDE Independence**: This approach allows developers to use Eclipse without module-related compilation errors while still producing proper modular JARs when building with Maven.
14+
15+
## How it works
16+
17+
The Maven build process:
18+
1. Compiles all regular Java sources from `src/main/java/`
19+
2. Adds `src/main/module-info/` as an additional source directory
20+
3. Compiles `module-info.java`
21+
4. Packages everything into a proper modular JAR
22+
23+
## For Developers
24+
25+
- **Eclipse users**: You don't need to worry about this file - Eclipse won't see it
26+
- **IntelliJ users**: IntelliJ handles modules better and can work with this setup
27+
- **Maven builds**: The module descriptor is automatically included in the final JAR
28+
29+
If you need to modify the module descriptor, edit `src/main/module-info/module-info.java` directly.

0 commit comments

Comments
 (0)