Martyn
Martyn

Reputation: 6383

`mvn package` giving Fatal error compiling: invalid flag: -parameters error

I've generated a spring boot project using the Initialzr tool. I've following allow this tutorial to the point where I've added a template and controller:

https://www.baeldung.com/spring-boot-start

Now I'm just trying to run mvn clean package but just seeing the following error in my command prompt:

...
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.501 s
[INFO] Finished at: 2019-06-17T11:03:12+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp: Fatal error compiling: invalid flag: -parameters -> [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

I've tried Googling some of the errors here as usually I can fix the issues but not really anything too informative here for me to grasp.

Below is my pom.xml file too encase there lies the problem:

<?xml version="1.0" encoding="UTF-8"?>
<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>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>My App</name>

    <properties>
        <java.version>1.8</java.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-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Upvotes: 7

Views: 3471

Answers (2)

In my case I did this:

  1. In pom.xml added the following lines:
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
  1. Go to the properties of the proyect -> Java Build Path -> Libraries
  2. Checked that the "JRE System Library[]" was using "JavaSE-1.8 (jre1.8.0_221) as JRE.
  3. Selected "JRE System Library" -> Click on "Edit..."
  4. Ticked the option "Alternate JRE:" and selected "jdk1.8.0_221".
  5. Saved everything, executed "Maven Clean" in the project and Installed Maven in the project.

After Eclipse downloaded the repositories of Maven, the build was successful.

Upvotes: 0

Veljko Antonijević
Veljko Antonijević

Reputation: 83

For me, the problem was that maven was using a different version of Java than the project.

After I changed it so that both maven and project are using the same versions of Java, everything worked fine.

The discrepancy in my case was that the project was on java 1.8 and maven was using java 1.7.

I changed the maven version of java directly since I needed to have an older version of Java set in Java Home. For that, I referred to this topic: How to set specific java version to Maven

I hope that this helps.

Upvotes: 5

Related Questions