Set a Property Based on Java Version for Maven Build


We switched from java 1.8 to openjdk 16. And we were faced with builds running on jdk1.8 and jdk16 simultaneously for a short period.

And the test didn’t run. So we had to pass arguments to surefire based on jdk the build was running. So we did it with a property whose value gets set based on the jdk.

Here is the code.

<profile>
           <id>properties-java8</id>
           <activation>
              	<jdk>1.8</jdk>        
           </activation>
           <properties>
	     	<argLine></argLine>
	   </properties>
       </profile>
       <profile>
           <id>properties-java16</id>
           <activation>
          	 	<jdk>16</jdk>              
           </activation>
            <properties>
	     	<argLine>--add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED</argLine>
	  	 </properties>
       </profile>

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.