0

I searched for other solutions on Stackoverflow but I am still having issues. I am trying to run with 1.7 but Maven is using 1.6. I am a bit out of ideas as of right now. Does anyone have any other suggestions?

pom.xml:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18.1</version>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
      <source>1.7</source>
      <target>1.7</target>
    </configuration>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.2</version>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>shade</goal>
        </goals>
        <configuration>
          <createDependencyReducedPom>false</createDependencyReducedPom>
          <artifactSet>
            <excludes>
              <exclude>org.hamcrest:*</exclude>
              <exclude>org.mockito:*</exclude>
              <exclude>org.objenesis:*</exclude>
            </excludes>
          </artifactSet>
          <filters>
            <filter>
              <artifact>*:*</artifact>
              <excludes>
                <exclude>META-INF/LICENSE</exclude>
                <exclude>META-INF/license</exclude>
                <exclude>META-INF/*.SF</exclude>
                <exclude>META-INF/*.DSA</exclude>
                <exclude>META-INF/*.RSA</exclude>
              </excludes>
            </filter>
          </filters>
          <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
              <manifestEntries>
                <Main-Class>com.mycompany.app.App</Main-Class>
                <Build-Number>1</Build-Number>
              </manifestEntries>
            </transformer>
          </transformers>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

When I try to mvn clean package or mvn clean install I get:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-appy: Fatal error compiling: invalid target release: 1.7 -> [Help 1]

With mvn -version the output is:

mvn -version

Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-11T13:58:10-07:00)
Maven home: /usr/local/Cellar/maven/3.2.3/libexec
Java version: 1.6.0_65, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.10.2", arch: "x86_64", family: "mac"

This is what others have suggested

echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.7.0_55.jdk/Contents/Home

Intellij -> preferences -> Compiler -> Java Compiler

enter image description here

$java -version
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)
Liondancer
  • 15,721
  • 51
  • 149
  • 255
  • 1
    You have 1.7 target defined either in pom file or in the project settings of idea. Apparently you can't use that with 1.6 JDK. Change the target bytecode to 1.6 – NeplatnyUdaj Mar 28 '15 at 00:56
  • Possible duplicate: http://stackoverflow.com/questions/18813828/why-maven-use-jdk-1-6-but-my-java-version-is-1-7 – NeplatnyUdaj Mar 28 '15 at 01:04
  • @NeplatnyUdaj After you suggestion, I am getting: `Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home/bin/java` – Liondancer Mar 28 '15 at 01:10
  • you obviously have 1.7.0_55 installed, not 40. – NeplatnyUdaj Mar 28 '15 at 01:45

1 Answers1

2

Apparently the Java used by your Maven is a Java 6, so it won't compile with a target 1.7.

You've set the JAVA_HOME apparently, but you need to make sure you're using the right java version, try java -version and make sure it's 1.7+

I've solved my multiple java versions headaches on OS X by using jEnv a tool to managed multiple java environments. You should give it a try and it's installable via Homebrew.

testinfected
  • 306
  • 1
  • 4
  • Give jEnv a try. You might want to activate the export plugin, which will automatically update your JAVA_HOME whenever you switch java runtimes – testinfected Mar 28 '15 at 01:05