I have a multi module maven setup and would like to execute a unit test for a library module. And here I am a bit stuck because one unrelated modules fails the build. Which leaves me with three options which all kind of suck:
Has anybdoy got an idea how I could improve the workflow.
2. If I use IntelliJ IDEA “Run Maven Goal” then the unit test is only executed when It passes. That is so because Maven will call the unit test as well. Sadly Maven won´t produce a nice output. And you won´t be able to just click and exception stack trace to go to the source code.
I am not quite understanding this part... the unit test is only executing when it passes? Can you elaborate on the comment "That is so because Maven will call the unit test as well." Pass or fail the unit test has to be called to run. Is it a case that the test passes when other tests are run, but fails when run individually? If so, I would humbly submit that you need to correct your unit tests. The issue of its failing may be a bad test and not bad code.
Note that you can pass an argument into maven to run just the one test, or a set of tests that match a pattern. See http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html To do this in IDEA, right click the test goal and select "Create 'my-module-name [test]'. In the run configuration dialog, add the switch for the desired test(s).Then run the goal using that Run Configuration via the Run button on the toolbar.
As for clicking on the stack trace, you can copy it, then select from the menu Analyze > Analyze Stacktrace... It will by default paste in the contents of the clipboard. (You may need to click normalize) Click OK. You will now have a stacktrace with links. If you do this often, you can map a keyboard shortcut to the 'Analyze Stacktrace' action in File > Settings > IDE Settings > Keymap for quicker access.
I hope that helps.
I am not quite understanding this part... the unit test is only executing when it passes?
A «mvn package» will execute all unit tests. If one of them fails then IntelliJ IDEA will abort. Only if running the tests in Maven passes then IntelliJ IDEA will call them a 2nd time. Which will be successfull as well.
Sorry, I'm still a bit confused by the part were you say "A «mvn package» will execute all unit tests . . .then IntelliJ IDEA will call them a 2nd time". (I'm not trying to be difficult here; just trying to understand your use case so I can help.) It sounds like you are you running the tests via a IntelliJ IDEA run configuration for the tests that has the "Before Launch" option set to "Run Maven Goal 'some-module:package'. That's the only way I can think of that mvn:package would run, and then IDEA would run the test(s). If so, can you change that goal to "compile" rather than "package"? (Or use the IDEA make?) That way maven does not run the tests causing the failure.
If not, another option would be to try and change the fail setting in the maven configuration. If you go into the Settings for the Maven (click on the wrench & gear icon in the Maven Tool window, or go to File > Settings > Project Settings > Maven), there is a setting for "Multiproject build fail policy". By default, that is set to "Fail Fast". The possible options are:
If you change that to "never fail", that might work to resolve the issue you are having.
I hope that helps.
If so, can you change that goal to "compile" rather than "package"?
That is a good idea. I try that (Thursday, I have two day off now — going to see Loreena McKennitt in Baden-Baden )
(Or use the IDEA make?)
Don't mind using IDEA make. But it will compile all the modules. And failed in an unrelated module. But it is not off my radar.
File > Settings > Project Settings > Maven), there is a setting for "Multiproject build fail policy".
I was looking for something like that — at all the wrong places. Looking at the wrong places for a setup is one of the problems I have with IntelliJ IDEA.