To what does Maven set the classpath for different goals?
My issue: I have a project that I am building in Jenkins. It gets checked out form SVN. As the next thing, a different file is checked out into workspace-root/mydir/my.properties
Then, maven test
is run.
In the test, a class loads the file by searching it on the classpath. Why does that work? (I'm new to Jenkins and maven and am trying to figure out how the job I'm looking at works...)
Maven uses the <dependencies/>
defined in your project as puts them on the classpath of the plugins. Furthermore, in the <plugin/>
section of each plugin, you can define additional <dependencies/>
which are only to be used by the plugin (and will therefore not become part of the final artifact in any way, or visible on the mvn dependency:tree
).
In regards to the tests, it's important to know that:
Resources under src/main/resources
and src/test/resources
are respectively copied to target/classes
and target/test-classes
. These two directories are added to your classpath. (The same is valid for src/main/java
and src/test/java
).
Each Maven plugin is executed in it's own classloader.
When executing tests, the maven-surefire-plugin
will usually fork your tests into a separate classloader.
Check this link.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments