Since I can't seem to think of a good way to explain this problem in conversation tone, I'll just explain it the clearest way that I can think of.
Notes:
1) this is computer stuff, so if you're not a programmer you might as well stop reading now.
2) this is discussion of a java project being built with maven.
So we have a common module (common) that is being used by 2 other modules (desktop and web). We want to put some helpers for generating filled out model classes in our common project where the model is, but we don't want to include that code in our production build. So we put that code in src/test/java. Now we want to reuse that code in our desktop and web module, but since it's not in the src/main/java branch, the code is never put into the final jar.
One (bad) solution is to just move this code into src/main/java, but like most things with maven there is an easier way to do it. We simply create a test-jar using the jar plugin as shown in the guide to using attached tests.
One "gotcha" that I found was I tried to quickly get this going so I used the switch -Dmaven.test.skip=true. This switch doesn't compile or run the tests. However, if you don't at least compile the tests, when you package them up you'll not have them in the test jar! So, if you have the unfortunate situation of having failing tests you can use the switch -Dmaven.test.failure.ignore=true.
No comments:
Post a Comment