John Patrick created MCOMPILER-421:
--------------------------------------

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


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)

Reply via email to