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!

4 Answers 4

0

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

1
  • 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, 2012 at 8: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

-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.

5
  • 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, 2012 at 8:54
  • Check if you are missing providerSelection configuration, more info in stackoverflow.com/questions/2199547/…
    – bbaja42
    Sep 12, 2012 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, 2012 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 groovy.codehaus.org/Groovy-Eclipse+compiler+plugin+for+Maven
    – bbaja42
    Sep 12, 2012 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, 2012 at 5:45
-1

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.