I am beginning to learn Maven and ran into a problem when I am trying to compile the test source code in a maven project.
My main java source code is dependent on a jar file so I have a dependency declared in my pom file as following:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany</groupId> <artifactId>myMavenApp</artifactId> <version>0.0.1-SNAPSHOT</version> <dependencies> <dependency> <groupId>com.mycompany.maven.testapp</groupId> <artifactId>domain</artifactId> <version>1.0</version> </dependency>
Compile error when compiling the test code:
[ERROR] \projects\news\publishing\src\test\java\com\mycompany\transformers\monitoring\JournalMonitorTest.java:[40,30] cannot find symbol [ERROR] symbol : class JournalMonitor [ERROR] location: class com.mycompany.transformers.monitoring.JournalMonitorTest
Compile error when compiling the test code (...)
JournalMonitor is neither provided by
com.mycompany.maven.testapp:domain:1.0:jar nor by the current project. It might help to clarify what artifact is providing this class. Please explain also how you "obtain" the
domain artifact. And keep in mind that artifacts with a fixed version like
1.0 are downloaded only once (vs
-SNAPSHOT artifacts) so make sure that the version you have in your local repository does contain the required stuff.
My test code also depends on the fooBar.jar.
fooBar.jar? Where is it declared? The POM snippet you posted doesn't reflect that. What does it have to do with the current problem anyway?
So with the above dependency, I can compile my main source code but not the test code. When I use test, I can compile test source but not the main application source.
Do you mean when changing the dependency scope to
test? This is very weird,
compile scoped dependencies (the default scope) are on the test classpath (see Dependency Scope).
Any ideas how one can do this?
You shouldn't have to do anything special for this use case. There is something else.
Well, I can't add comments for some reason. I am very new at this so I am just going to post an answer instead of a comment. Thanks a lot Pascal for your answer. You were correct that maven handles this w/o me doing anything special. Problem was that I did not give you guys all the details. The tests that were failing to compile had issues (they were committed in trunk but don't build to being with). And I was trying to port the application (ant based build) to maven. It was painful but it thought me a lesson. Never assume. I got lots of learning to do with maven. I wish I could vote for your answer, but I can't.