[
https://issues.apache.org/jira/browse/MCOMPILER-421?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17146838#comment-17146838
]
John Patrick commented on MCOMPILER-421:
----------------------------------------
I've created a sample project showing the issue.
https://github.com/nhojpatrick/org.apache.maven_maven-compiler-plugin_MCOMPILER-422
The commands you need are shown below, I'm using a mac so to change JAVA_HOME
you'll need to adapt this to your OS.
I've provided expected of what I believe should work, and to workaround
examples, with the only difference between then being the module-info.java uses
provides.
I build and tests using Java 1.8, then again using Java 11. So I know the code
and tests work for both 1.8 and 11. I'm working on a patch for surefire so it
can do executions and be given the jdk toolchain, if I'm able to get that
working then it might make this issue irrelevant. Because I won't need to 2nd
clean install using Java 11.
Working 'workaround';
{code}
$ JAVA_HOME=`/usr/libexec/java_home -v "1.8"` ;
$ ./mvnw -f workaround-no-provides/pom.xml clean install ;
...
$
$ JAVA_HOME=`/usr/libexec/java_home -v "11"` ;
$ ./mvnw -f workaround-no-provides/pom.xml ;
...
$
{code}
Failing 'workaround' with provides;
{code}
$ JAVA_HOME=`/usr/libexec/java_home -v "1.8"` ;
$ ./mvnw -f workaround-no-provides/pom.xml clean install ;
...
$
$ JAVA_HOME=`/usr/libexec/java_home -v "11"` ;
$ ./mvnw -f workaround-no-provides/pom.xml ;
...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR]
PATH/org.apache.maven_maven-compiler-plugin_MCOMPILER-422/workaround-with-provides/service-implementation/src/main/java11/module-info.java:[4,43]
error: cannot find symbol
symbol: class ExampleServiceImpl
location: package tld.example.implementation
[INFO] 1 error
...
$
{code}
If I remove the ModuleInfoHack.java file so the 'expected' version, it fails
earlier;
{code}
$ JAVA_HOME=`/usr/libexec/java_home -v "1.8"` ;
$ ./mvnw -f workaround-no-provides/pom.xml clean install ;
...
$
$ JAVA_HOME=`/usr/libexec/java_home -v "11"` ;
$ ./mvnw -f workaround-no-provides/pom.xml ;
...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR]
PATH/org.apache.maven_maven-compiler-plugin_MCOMPILER-422/expected/service-interfaces/src/main/java11/module-info.java:[2,23]
error: package is empty or does not exist: tld.example.interfaces
[INFO] 1 error
...
$
{code}
> multi release jar issue with module-info.java when using provides
> -----------------------------------------------------------------
>
> Key: MCOMPILER-421
> URL: https://issues.apache.org/jira/browse/MCOMPILER-421
> Project: Maven Compiler Plugin
> Issue Type: Improvement
> Affects Versions: 3.8.1
> Reporter: John Patrick
> Priority: Major
>
> If you have the following structure you have to recompile everything for each
> version supported.
> If you have the following code;
> {code}
> src/main/java/package/Service.java (1)
> src/main/java/package/Example.java (2)
> src/main/java/package/Java1dot8.java (3)
> src/main/java11/package/Example.java (4)
> src/main/java11/package/Java11.java (5)
> src/main/java11/module-info.java (6)
> src/main/java14/package/Example.java (7)
> src/main/java14/package/Java14.java (8)
> src/main/java14/module-info.java (9)
> {code}
> I expect the following jar structure;
> {code}
> package/Service.class (1)
> package/Example.class (2)
> package/Java1dot8.class (3)
> META-INF/versions/11/package/Example.java (4)
> META-INF/versions/11/package/Java11.java (5)
> META-INF/versions/11/module-info.java (6)
> META-INF/versions/14/package/Example.java (7)
> META-INF/versions/14/package/Java14.java (8)
> META-INF/versions/14/module-info.java (9)
> {code}
> Using the following maven configuration;
> {code}
> <executions>
> <execution>
> <id>java11-main</id>
> <phase>compile</phase>
> <goals>
>
> <goal>compile</goal>
> </goals>
> <configuration>
>
> <release>11</release>
> <jdkToolchain>
>
> <version>11</version>
> </jdkToolchain>
>
> <compileSourceRoots>
>
> <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
>
> </compileSourceRoots>
>
> <multiReleaseOutput>true</multiReleaseOutput>
> </configuration>
> </execution>
> <execution>
> <id>java14-main</id>
> <phase>compile</phase>
> <goals>
>
> <goal>compile</goal>
> </goals>
> <configuration>
>
> <release>14</release>
> <jdkToolchain>
>
> <version>14</version>
> </jdkToolchain>
>
> <compileSourceRoots>
>
> <compileSourceRoot>${project.basedir}/src/main/java14</compileSourceRoot>
>
> </compileSourceRoots>
>
> <multiReleaseOutput>true</multiReleaseOutput>
> </configuration>
> </execution>
> </executions>
> {code}
> But due to needing to use provides and uses in the module-info.java
> {code}
> module MODULE_A {
> exports PACKAGE_A;
> uses PACKAGE_B.Service;
> provides PACKAGE_B.Service
> with PACKAGE_A.ServiceImpl;
> }
> {code}
> I get compile errors with src/main/java11/module-info.java as that class is
> under src/main/java. So I need to change it to something like this so the
> compile see classes already compiled that are in target/classes;
> {code}
> <executions>
> <execution>
> <id>java11-main</id>
> <phase>compile</phase>
> <goals>
>
> <goal>compile</goal>
> </goals>
> <configuration>
>
> <release>11</release>
> <jdkToolchain>
>
> <version>11</version>
> </jdkToolchain>
>
> <compileSourceRoots>
>
> <compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
>
> <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
>
> </compileSourceRoots>
>
> <multiReleaseOutput>true</multiReleaseOutput>
> </configuration>
> </execution>
> <execution>
> <id>java14-main</id>
> <phase>compile</phase>
> <goals>
>
> <goal>compile</goal>
> </goals>
> <configuration>
>
> <release>14</release>
> <jdkToolchain>
>
> <version>14</version>
> </jdkToolchain>
>
> <compileSourceRoots>
>
> <compileSourceRoot>${project.basedir}/src/main/java</compileSourceRoot>
>
> <compileSourceRoot>${project.basedir}/src/main/java11</compileSourceRoot>
>
> <compileSourceRoot>${project.basedir}/src/main/java14</compileSourceRoot>
>
> </compileSourceRoots>
>
> <multiReleaseOutput>true</multiReleaseOutput>
> </configuration>
> </execution>
> </executions>
> {code}
> Which then produces a jar looking something like this;
> {code}
> package/Service.class (1)
> package/Example.class (2)
> package/Java1dot8.class (3)
> META-INF/versions/11/package/Java1dot8.class (3)
> META-INF/versions/11/package/Example.java (4)
> META-INF/versions/11/package/Java11.java (5)
> META-INF/versions/11/module-info.java (6)
> META-INF/versions/14/package/Java1dot8.class (3)
> META-INF/versions/14/package/Java11.java (5)
> META-INF/versions/14/package/Example.java (7)
> META-INF/versions/14/package/Java14.java (8)
> META-INF/versions/14/module-info.java (9)
> {code}
> One of the projects that needs this is
> https://github.com/nhojpatrick/nhojpatrick-cucumber/tree/feature/surefire-3.0.0-M5
> The actual module-info.java using provides is
> https://github.com/nhojpatrick/nhojpatrick-cucumber/blob/feature/surefire-3.0.0-M5/json-transformations/remove/src/main/java11/module-info.java
--
This message was sent by Atlassian Jira
(v8.3.4#803005)