'Run maven cucumber tests from IntelliJ

I have a maven project, which run cucumber tests using JUnit runner. I can use the following syntax from command line to run the tests:

mvn -Dcucumber.options="--tags @Sanity" test

This works perfectly fine when run from the console. Now I'm trying to set up Maven runner configuration in IntelliJ IDEA to do the same - and I just can't get it to work. According to the IntelliJ documentation, I need to \-escape double quotes - so in the command line I specify -Dcucumber.options=\'--tags @Sanity\' test

Maven is executed - but produces this error message:

Unknown lifecycle phase "@Sanity""

It appears that the parameter is unescaped before being passed to maven. I then tried to putting the entire thing in quotes, specifying parameters as '-Dcucumber.options=\"--tags @Sanity\"' test. This results in the following error:

Unknown lifecycle phase "'-Dcucumber.options="--tags"

Again, I guess, something is with quoting/escaping. I then tried these options: "-Dcucumber.options='--tags @Sanity'" test - this time maven goes through the compilation stage and seemingly attempts to run tests - but then fails with the following error:

Tests in error: 

initializationError(com.mycompany.mypackage.MyRunner): Unknown option: --tags @Sanity

I tried all sorts of quoting/escaping/double-escaping/double-quoting/etc. - to no avail.

Again, running maven from command line works fine - I am specifically interested in setting it up as a runner configuration in IntelliJ IDEA.



Solution 1:[1]

You need to escape space character: mvn "-Dcucumber.options=--tags\ @Sanity" test

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 y.bedrov