java - How to package test classes into the jar without running them? -
i'm struggling including test classes jar package, not running them. after googling, i've tried mvn package -dskiptests
, test classes not added jar.
any ideas?
if youre following maven conventions test classes under src/test/java
. maven never packages contents of test sources subdirectory artifact.
you have (at least ...) 3 alternativs:
put tests "normal" sources
if really want them packaged (why?) should place test classes under src/main/java
treated normal source , compiled classes packaged artifact (usually *.jar)
you imght run sorts of issues doing this. example artifact have compile-scoped dependency on junit, might interfere other modules using jar.
also, might have configure maven plugins running tests aware of test classes if (that if ever want run tests part of build). example surefire , failsafe plugins.
configure maven jar plugin build tests jar
see maven jar plugin documentation. have section titled "how create jar containing test classes" - instructions there cause tests packaged separate jar file (which better idea).
create jar way using assembly plugin directly
yuo disable default execution of jar plugin , instead add execution of assembly plugin package phase create jar. need write assembly descriptor (not complicated above link makes out be). give yu full control on included in jar produced. best start copying 1 of predefined assemblies
Comments
Post a Comment