[MCOMPILER-402] Not possible to exclude module-info with 'excludes'
Petr Dolezal opened MCOMPILER-402 and commented
I tried to use excludes to exclude module-info.java from build, essentially in the same way as described in the official example, but the file was always compiled anyway. I even tried to use various patterns with no effect.
This seems weird to me and with the respect to the mentioned example I consider such a behavior to be a bug.
Since I could not attach the source files, here is the listing for reproducing the issue:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>com.example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<source>11</source>
<target>11</target>
<excludes>
<exclude>module-info.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
// src/main/java/module-info.java
module com.example {
exports com.example;
}
// src/main/java/com/example/Main.java
package com.example;
public final class Main {
public static void main(String... args) {
System.out.println("Hello World");
}
}
Affects: 3.8.0, 3.8.1
Issue Links:
- MCOMPILER-488 dedicated option for
implicitjavac flag
Remote Links:
Robert Scholte commented
Interesting... output says [INFO] Compiling 1 source file to ... but in the end there are 2 class files.
Piotr Zygielo commented
Here is my guess.
The same with CLI:
$ rm -rf target/classes/*
$ javac -d target/classes -sourcepath src/main/java:target/generated-sources/annotations: -s target/generated-sources/annotations -g -nowarn --release 11 src/main/java/com/example/Main.java
$ tree target/classes
target/classes
├── com
│ └── example
│ └── Main.class
└── module-info.class
So module-info.java is not sent for compilation by the plugin, but it's being found by compiler itself.
https://docs.oracle.com/javase/7/docs/technotes/tools/solaris/javac.html#searching
You can use the -implicit option to specify the behavior.
And it helps:
$ rm -rf target/classes/*
$ javac -d target/classes -sourcepath src/main/java:target/generated-sources/annotations: -s target/generated-sources/annotations -g -nowarn --release 11 src/main/java/com/example/Main.java -implicit:none
$ tree target/classes
target/classes
└── com
└── example
└── Main.class
As there is currently no option to configure -implicit in mojo I suggest to use https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#compilerArgs to do it explicitly.
Piotr Zygielo commented
essentially in the same way as described in the official example
How I see it: reproducer in this issue is very different, not the same at all, in several aspects:
- example sets default release as 6 (reproducer: 11)
- example has two executions, with the first including MI, targeting release 9 where the idea of MI is known,
- example excludes MI in separate execution, which targets release 6, where there is no such thing as MI at all.
Thus I propose to reclassify this report as New Feature/Enhancement to support implicit option in m-c-p configuration - this could be provided by PR#102.
-To complete the fix - perhaps the example could be updated then to use implicit there.-
(After having glass of cold water now I think example needs no modification as it's fine as is.)