Pour pouvoir compiler en JDK7 alors que la version par défaut du système est en 6 vous devez surcharger le plugin maven-compiler-plugin et préalablement déclaré une variable d'environnement JAVA_HOME_7 pointant vers le répertoire d'installation de votre JDK.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>"${env.JAVA_HOME_7}/bin/javac"</executable>
<compilerVersion>1.7</compilerVersion>
<compilerArguments>
<encoding>${project.build.sourceEncoding}</encoding>
</compilerArguments>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
Le plugin maven-surefire-plugin a le même problème, il n’utilise pas la version définie dans le plugin maven-compiler-plugin mais la version du JDK par défaut
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_HOME_7}/bin/java</jvm>
</configuration>
</plugin>
java.lang.reflect.UndeclaredThrowableException
at $Proxy0.invoke(Unknown Source)
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:145)
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcess(SurefireStarter.java:87)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:69)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.ProviderFactory$ClassLoaderProxy.invoke(ProviderFactory.java:103)
... 4 more
Caused by: java.lang.UnsupportedClassVersionError: com/boiron/ggr/commons/DateUtilTest : Unsupported major.minor version 51.0
Par contre si vous utilisez des outils d'audit de code tel que Sonar, Corbertura, Emma... susceptibles de faire de l'instrumentation du code généré vous pouvez avoir une autre exception du type :
java.lang.VerifyError: Expecting a stackmap frame
Pour éviter cette erreur vous pouvez rajouter l'option -XX:-UseSplitVerifier à l'exécution du plugin maven-surefire-plugin (voir http://www.oracle.com/technetwork/java/javase/tech/vmoptions-jsp-140102.html)
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_HOME_7}/bin/java</jvm>
<argLine>-XX:-UseSplitVerifier</argLine>
<argLine>-XX:-UseSplitVerifier</argLine>
</configuration>
</plugin>
Aucun commentaire:
Enregistrer un commentaire
Remarque : Seul un membre de ce blog est autorisé à enregistrer un commentaire.