Where to add compiler options like -ea in IntelliJ IDEA?

JavaIntellij Idea

Java Problem Overview


I want to add the -ea option. I set it in Project Settings --> Compiler --> Java Compiler : Additional command line parameters.

But it caused a make error: invalid flag: -ea. P.S.: the above error message may not be the same as yours, because IntelliJ showed error in my native language, not English. I translated it into English.

Java Solutions


Solution 1 - Java

The -ea option to enable assertions is passed to the JVM not to the compiler. Add it as a VM option for your runtime configuration.

Specific location in the menu: Run > Edit Configurations... > Configuration > VM options:

Where to put the -ea flag

Solution 2 - Java

You can also make IntelliJ IDEA support assertions by default by changing the default Application configuration:

In the top menu, press Run > Edit Configurations > Defaults > Application > VM options.

To enable the assertion feature for all application, you could just fill the VM options with -ea

Solution 3 - Java

For IntelliJ IDEA 2020.3:

  • Run -> Edit Configurations... -> Modify options -> Add VM options.
  • Input -ea then click OK button.

enter image description here

Solution 4 - Java

Build, Execution, Deployment -> Compiler -> Java Compiler -> Override compiler parameters per-module -> +

Your project name is module name. And add -ea to the Compilation options for javac

It works for IDEA 2021.2, Fedora linux x86_64, OpenJDK 1.8 64bit

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionduleshiView Question on Stackoverflow
Solution 1 - JavaDevView Answer on Stackoverflow
Solution 2 - JavaneoView Answer on Stackoverflow
Solution 3 - JavaJimmy_RwView Answer on Stackoverflow
Solution 4 - JavaNick DongView Answer on Stackoverflow