Sat, 23 Jul 2022 19:28:50 +0300, /Stanimir Stamenkov/:
I want to produce a Java 8 compatible library that provides some Java 9+
classes, packaged as a Multi-Release JAR:
* https://maven.apache.org/plugins/maven-compiler-plugin/multirelease.html
O.k. From the very same page:
*Challenges*
* The Multi-Release: true attribute is only recognized when the
classes are in a jar. In other words, you cannot test the classes put in
target/classes/META-INF/versions/${release}/.
I may try adding target/classes/META-INF/versions/${release}/ as a
test-resource directory using the build-helper-maven-plugin and see how
far I could get it.
I've taken a slimmed down _Multi-Release Parent_
<http://www.russgold.net/sw/2018/04/easier-than-it-looks/> approach, and
the main compilation and packaging seems just right:
The following may be of use to someone. I've noticed the following
shortcoming with the original configuration suggested in the given
approach – the sources JAR and javadoc don't include the extra source
compiled. I've used the build-helper-maven-plugin [1] to add
src/main/java9/ as source directory and adjusted the default-compile
execution similarly to compile only the main sources:
<execution>
<id>default-compile</id>
<configuration>
<release>${base.java.version}</release>
<compileSourceRoots>
<compileSourceRoot>${project.build.sourceDirectory}</compileSourceRoot>
</compileSourceRoots>
</configuration>
</execution>
See: https://github.com/stanio/xbrz-java/commit/61b352e94
Also, I had to fix the javadoc tool version > base.java.version (which
is fine):
* https://github.com/stanio/xbrz-java/blob/da1264fbd/pom.xml#L131-L135
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
<executions>
<execution>
<id>compile-java9</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>9</release>
<jdkToolchain>
<version>9</version>
</jdkToolchain>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java9</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<archive>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
Now I've added some test sources exercising the Java 9+ only classes,
but the `testCompile` goal seems unable to find them. Is it possible to
configure the `default-testCompile` execution to see the classes from
the `multiReleaseOutput` of the main compile?
[1] https://www.mojohaus.org/build-helper-maven-plugin/
--
Stanimir
Remove .INVALID from my address to reply directly to me, but it is
probably best to reply just to the mailinig list.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org