Ajay K
Ajay K

Reputation: 85

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile in Spring

I am working on a Spring security project in STS. I am trying to build my project but I am getting the following exception. Error log,

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.288 s
[INFO] Finished at: 2015-11-27T09:41:59+05:30
[INFO] Final Memory: 21M/227M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project spring-data-rest-security: Fatal error compiling: invalid target release: 1.8 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

My pom.xml file is

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>spring-data-rest-security</artifactId>

    <name>Spring Data REST - Security Example</name>

    <parent>
        <groupId>org.springframework.data.examples</groupId>
        <artifactId>spring-data-rest-examples</artifactId>
        <version>1.0.0.BUILD-SNAPSHOT</version>
    </parent>

    <properties>
        <spring-security.version>4.0.2.RELEASE</spring-security.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
        </dependency>

    </dependencies>

</project>

I read answers of similar issues but none of them seem to work. Kindly help me out.

Upvotes: 0

Views: 3336

Answers (2)

Vishal
Vishal

Reputation: 2173

That would not help. I had the same issues and my %JAVA_HOME% pointed to jdk1.8.0_45. I also had java version 1.8 language version 8 in IntelliJ "Project Settings >> Build, Execution, Deploy >> Module Compiler Version" and "Project Structure >> Modules >> Source". However this did not fix my issue.

As per this apache resource, it looks like that default source setting after Maven 3.0 is 1.5 that needs a manual override using pom.xml. I explicitly provided source and targer release to 1.8 in my pom.xml and it DID fix my issue.

 <plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.3</version>
  <configuration>
     <source>1.8</source>
     <target>1.8</target>
  </configuration>
 </plugin>

Upvotes: 1

Saša Zejnilović
Saša Zejnilović

Reputation: 920

Do this in your cmd line C:\mvn>echo %JAVA_HOME% if the output is something like C:\Program Files\Java\jdk1.X... where X is anything but number 8, then you are trying to build it with wrong jdk version.

Install jdk 1.8 and make sure your %JAVA_HOME points to that or drop the target release to 1.X.

Upvotes: 1

Related Questions