I have a java program that is built using Maven and I need to enable the assert
keyword. Ideally, I'd want to enable assertions in the maven build command.
To configure assertion options one must use either the -ea or -da command line flags to enable or disable assertions with the command line tool: “java”. For example, “java -ea Assert” where Assert is a java class file. You may also specify a specific class or package as follows.
You can use the command-line arguments –ea (for enabling assertions) and –da (for disabling assertions) with other options for classes, packages, and system classes when running the program.
Enabling and Disabling AssertionsBy default, assertions are disabled at runtime. Two command-line switches allow you to selectively enable or disable assertions. Enables or disables assertions in all classes except system classes.
Maven compiles and builds the java code. Assertion errors come when you are actually running java code so with maven you can't do it this way
unless you are using maven plugin to launch java code, you would have to supply -ea
to jvm
exec:java
Pass -ea
to commandline argument
Surefire
if you meant for test execution then configure sure-fire plugin to pass -ea
to jvm
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<enableAssertions>true</enableAssertions>
</configuration>
</plugin>
The only things that worked for me was
export MAVEN_OPTS="-ea"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With