2

Is it possible to force the gmaven plugin to use a different JDK than the one specified in JAVA_HOME? We need to build a specific project using Java 7, but most developers will have JAVA_HOME set to a Java 6 install as all our other projects are still on Java 6.

The error message we get is:

[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs (default) on   project XYZ: Execution default of goal org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs failed: An API incompatibility was encountered while executing org.codehaus.gmaven:gmaven-plugin:1.4:generateStubs: java.lang.UnsupportedClassVersionError: <snip> : Unsupported major.minor version 51.0

Thanks!

Malakim
  • 1,333
  • 2
  • 18
  • 34

4 Answers4

0

The Maven Enforcer plugin is an easy way to require a specific JDK version.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
  • Yes, it will fail the build if it detects 1.6 being used - but it won't help us to actually set the JDK to use for the build. Unless we miss something... – Malakim Sep 12 '12 at 08:55
0

you can specify JAVA_HOME for maven task in ide or bat/sh file for example Intellige Idea

and no need to change system environment variables

Xsires
  • 46
  • 3
-1

Example configuration from maven-compiler-plugin

<project>
  [...]
  <build>
    [...]
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
    [...]
  </build>
  [...]
</project>

The maven by default uses Java 1.4, not the Java set in the JAVA_HOME variable.

bbaja42
  • 2,099
  • 18
  • 34
  • 1
    Sure, but the Groovy plugin seems to ignore the maven compiler plugin settings (where we specify JDK 1.7) and happily use JDK 1.6 for stub generation – Malakim Sep 12 '12 at 08:54
  • Check if you are missing providerSelection configuration, more info in http://stackoverflow.com/questions/2199547/maven-compile-mixed-java-groovy-1-7-project-using-gmaven-plugin – bbaja42 Sep 12 '12 at 11:27
  • We tried that as well - no luck. I assumed this only sets the version of Groovy to use, is that in some way tied to what JDK is used to compile the code? – Malakim Sep 12 '12 at 11:39
  • Well, if it is still not working, I would say it is a bug in the gmaven-plugin or somewhere in your configuration. There is an alternative to gmaven, which is more actively developed http://groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven – bbaja42 Sep 12 '12 at 11:59
  • Could very well be a bug - if we set JAVA_HOME to point to a JDK 7 installation it builds fine. So my guess it that the gmaven plugin just uses whatever it finds there. – Malakim Sep 13 '12 at 05:45
-1

You can set an alternate jdk in the maven-complier-plugin configuration. See here

Mr. Matt
  • 7
  • 1
  • See my comments in bbaja42's answer - the mvn compiler plugin config does not carry over to the gmaven plugin. – Malakim Sep 19 '12 at 10:47