I have a Maven project running on jdk22
for which I try to generate JavaDocs on Gitlab with CI/CD.
This is my .gitlab-ci.yml
image: maven:latest
pages:
stage: deploy
script:
- mvn javadoc:aggregate # Generate Javadocs
- mkdir public # GitLab Pages requires your site to be in a 'public' directory
- cp -r target/site/apidocs/* public # Copy Javadocs to the 'public' directory
artifacts:
paths:
- public
only:
- main
This is the relevant part from my pom.xml
...
<modules>
<module>core</module>
<module>shell</module>
<module>storage</module>
<module>json</module>
<module>utility</module>
</modules>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>tests</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>
...
And this the log from the failed pipeline execution.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.11.0:compile (default-compile) on project core: Fatal error compiling: error: invalid target release: 22 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
It seems as if the maven compiler plugin has problems with jdk22
. Is this version not supported as it is still in early access?
The simple problem here is that at the moment (time of writing this anser) no EA build of JDK 22 simply exist...
Updated:
Some hints. If you already use properties like:
<properties>
<maven.compiler.source>22</maven.compiler.source>
<maven.compiler.target>22</maven.compiler.target>
</properties>
You don't need to define this:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>22</source>
<target>22</target>
</configuration>
</plugin>
</plugins>
since JDK9+ you should use:
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>
Also a plugin should be defined in pluginManagement instead.
Also convention over configuration has a lot of advantages. Every project has the same structure and that makes it easier to understand and to on-board. So I strongly recommend to follow convention-over-configuration. (default directory layout!)