title: Maven compilation error: package does not exist
body: <p>I'm trying to add maven support to an existing enterprise project. It is a multi-module project, and the first 2 modules compile and package without problems, but I'm facing the Compilation Error I try to use the same dependency in more than one module.
  My structure is:</p>
  
  <pre><code>&gt; + parent
  &gt;    - pom.xml
  &gt;    - module-1
  &gt;    -   pom.xml
  &gt;    - module-2  (Depends on module-1)
  &gt;    -   pom.xml
  &gt;    - module-3
  &gt;    -   pom.xml (Depends on both modules 1 and 2)
  </code></pre>
  
  <p>I'm with the project opened on Eclipse and it shows no errors. When I run <code>mvn clean install</code> from the parent, it succesfully installs both module 1 and 2, but fails on module 3 saying that <code>package xxx.yyy does not exist</code> and <code>Cannot find symbol XXXYYY</code>. The package xxx.yyy and the symbol XXXYYY are inside a jar that is listed on the dependencies of both modules 2 and 3.</p>
  
  <p>Since both modules depende on same jar, I tried to add the dependency only on module 2 and I believe that module 3 should be seeing it because of transitive dependencies, but it couldn't see the package. So I tried to add the dependency to both module 2 and 3 poms and the problem persisted.</p>
  
  <p>I've already checked/tried these:</p>
  
  <ul>
  <li>The requested jar is listed in my dependecies. I've ran the following command and after that I can see the required .jar file on the list of dependencies: <code>mvn dependency:copy-dependencies</code></li>
  <li>As I said above, I tried to put in my classpath through the transitive dependency and referencing it directly on my pom and both solutions didn't work</li>
  <li>I tried to delete my whole repository and download everything again and also didn't work</li>
  </ul>
  
  <p>The only particularity of my project is that module 3 depends on module 2 and depends on a lib that module 2 also depends.</p>
  
  <p>Below I'm pasting the poms from both module 2 and 3. I've changed some names, because of company policy.</p>
  
  <p><strong>Module-2</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" ... &gt;  
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
      &lt;groupId&gt;com.company&lt;/groupId&gt;
      &lt;artifactId&gt;parent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;/parent&gt;
  
    &lt;artifactId&gt;Module2&lt;/artifactId&gt;    
    &lt;dependencies&gt;
  
        &lt;dependency&gt;
            &lt;groupId&gt;com.company&lt;/groupId&gt;
            &lt;artifactId&gt;Module1&lt;/artifactId&gt;
            &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
        &lt;/dependency&gt;         
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.company&lt;/groupId&gt;
          &lt;artifactId&gt;SharedArtifact&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
       &lt;/dependency&gt;
  
      ...
  </code></pre>
  
  <p><strong>Module-3</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" ... &gt;  
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;parent&gt;
      &lt;groupId&gt;com.company&lt;/groupId&gt;
      &lt;artifactId&gt;parent&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;/parent&gt;
  
    &lt;artifactId&gt;Module3&lt;/artifactId&gt;    
    &lt;dependencies&gt;
  
        &lt;dependency&gt;
            &lt;groupId&gt;com.company&lt;/groupId&gt;
            &lt;artifactId&gt;Module2&lt;/artifactId&gt;
            &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
        &lt;/dependency&gt;         
  
      &lt;!--&lt;dependency&gt;
          &lt;groupId&gt;com.company&lt;/groupId&gt;
          &lt;artifactId&gt;SharedArtifact&lt;/artifactId&gt;
          &lt;version&gt;1.1&lt;/version&gt;
       &lt;/dependency&gt;--&gt;
  
      ...
  </code></pre>
  
  <p>And the package that can't be seen is inside the 'SharedArtifact'. When I remove the dependency from Module2, it doesn't gives the <code>package does not exist</code> error from the 'SharedArtifact' package. But then it gives the <code>package does not exist</code> from the Module2 jar. </p>
  
  <p>It looks like that somehow the dependencies are getting lost since the Module3 depends on them both.</p>
  
  <p>I'm using <strong>Java 1.6.0_29</strong> and <strong>Maven 3.0.5</strong>. And I can't upgrade to Java 7, because the project needs Java 6. And can't upgrade Maven, cause upgraded Maven only works with java 7 and higher.</p>
  
  <p><strong><em>Update 1:</em></strong></p>
  
  <p>The error given when I compile is the following:</p>
  
  <pre><code>[ERROR] COMPILATION ERROR :
  [INFO] -------------------------------------------------------------
  [ERROR] \Users\usuario\Documents\workspaces\myworkspace\qa\Module3\src\com\company\sharedartifact\package\SomeClass.java:[8,55] 
  package com.company.sharedartifact.package  does not exist
  [ERROR] \Users\usuario\Documents\workspaces\myworkspace\qa\Module3\src\com\company\sharedartifact\package\SomeClass.java:[9,55] 
  package com.company.sharedartifact.package does not exist
  [ERROR] \Users\usuario\Documents\workspaces\myworkspace\qa\Module3\src\com\company\sharedartifact\package\SomeClass.java:[17,85] 
  cannot find symbol
  symbol  : class SomeOtherClass
  </code></pre>
  
  <p>I can't paste the whole -X log because of company policy, but if some part is necessary, I can change some names.</p>
  
  <p><strong><em>Update 2:</em></strong></p>
  
  <p>Today I just figured out that if a run <code>mvn clean install</code>, it fails to compile. But if I run <code>mvn clean</code>, then (in Eclipse) I run <code>Maven Update project</code> and then `mvn install, it compiles!</p>
  
  <p>Since I found this, I've already referred to <a href="https://stackoverflow.com/questions/15532534/maven-why-after-mvn-clean-i-need-to-execute-maven-update-project-before-m">this question</a> and I believe that something is wrong with my classpath. As I'm working with a Weblogic Portal application, I need to keep some Shared Libraries (those that are needed both by project and runtime) on Eclipse. Possibly some library is being forgotten on my pom. The weird thing is that the package that the compilation claims that doesn't exist, DOES exist.</p>