Reputation: 4747
I am trying to understand the maven build lifecycle when it is regarding to tests: Let's say I have a project with a class in the src/main folder and another one in the src/test. When I run mvn install, it get's compiled, then tested, then packaged and installed.
Until now I thought that maven would not package the tests in the snapshot, because this is not "production" code. Is this true? In this case, when does maven ignores the test files?
Upvotes: 2
Views: 37
Reputation: 137269
What you said about the Maven lifecycle is true. The "main" phases include:
compile
: in this phase, the maven-compiler-plugin:compile
goal is run which compiles the main code of the project.test-compile
: in this phase, the maven-compiler-plugin:testCompile
goal is run which compiles the test code of the project.test
: in this phase, the maven-surefire-plugin:test
goal is run and all the unit tests are executed.package
: in this phase, the maven-jar-plugin:jar
goal is run and creates a JAR of the current project. By default, this JAR will include all classes under target/classes
, which contains all the main classes, but not the test classes which are located inside target/test-classes
. You could say that it is at this step that Maven ignores the test classes.install
: in this phase, the maven-install-plugin:install
will install the main artifact, and every attached artifact, into your local repository.To answer more precisely, it's not that Maven ignores the test classes, it is that by default, the packaging process only considers the main classes. But you can configure it to also package the test classes with the maven-jar-plugin:test-jar
goal inside another attached artifact.
Upvotes: 2