The POM is only used when publishing an artifact; it gets uploaded to the Maven repo along with the artifact. Therefore, the POM only needs runtime dependencies.
Gradle executes tests independent of your deployment plugin, so it does not use the POM file.
Assuming you're using the Java plugin, it adds the test
source set. This in turn creates the testCompile task.
Now, Gradle assumes that your runtime dependencies will be the same as your compile-time dependencies, if you don't configure otherwise. However, it only considers the main
source set. That's why you POM doesn't include test
dependencies.
So, in summary, configure your test dependencies similar to the below. Then, just live happy, knowing that the published artifact will not include your test code or its dependencies.
dependencies {
testCompile 'org.springframework:spring-test:4.+'
}
If you have an exceptional situation, where tests are executed on a machine that doesn't have access to the test source code, please describe in more detail what your requirements are. It should be possible to set up a separate output artifact for the test code, so it can be published, but I still don't think you should release it in the same package (or POM) as the main
source set.