66

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.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
duleshi
  • 1,966
  • 2
  • 21
  • 32

4 Answers4

94

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 <code>-ea</code> flag

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
Dev
  • 11,919
  • 3
  • 40
  • 53
  • can this configuration be modified during unit tests started with gradle for example? – Dinesh Nov 29 '17 at 13:35
  • Don't forget to hit save icon after adding -ea. – Swapnil Chaudhari Aug 21 '19 at 08:54
  • In my specific case (`assert` commands to enable in the middle of some Kotlin code), I had to `Add new` configuration first, and then select `Kotlin`. After that, I could see some form showing the `VM Options` field as suggested here, in which to add the `-ea` option. – Olivier Dec 06 '22 at 16:42
10

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

Stefan van den Akker
  • 6,661
  • 7
  • 48
  • 63
neo
  • 360
  • 3
  • 9
8

For IntelliJ IDEA 2020.3:

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

enter image description here

Jimmy_Rw
  • 981
  • 9
  • 7
0

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

Nick Dong
  • 3,638
  • 8
  • 47
  • 84