title: How is it possible that Maven builds classes that are not in my project?
body: <p>I'm seeing an extremely strange issue with Maven today: it's trying to build classes that are not in my project, but coming from dependencies. <code>mvn compile</code> crashes with:</p>
  
  <pre><code>...
  [ERROR] COMPILATION ERROR :
  [INFO] -------------------------------------------------------------
  [ERROR] AppConstants.java):[4,12] unmappable character for encoding UTF-8
  ...
  </code></pre>
  
  <p>There is no <code>AppConstants.java</code> in my project, and a search with <code>grep -r AppConstants .</code> gives no results. The class exists in another artifact that's a dependency of my project.</p>
  
  <p>I managed to get my project to compile by passing <code>-Dproject.build.sourceEncoding=Cp1252</code> to <code>mvn compile</code>, but this is not a solution, because my project should use <code>utf-8</code> encoding. Sure enough, when compiled this way I see <code>AppConstants.class</code> under <code>target/classes/</code> but where can it come from? How is this possible?</p>
  
  <p>Nothing changed in the pom of the project recently, but I know that the dependent project is working on migrating to Maven these days. What could be going on?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>There is no <code>AppConstants.java</code> file in my project, and <code>AppConstants</code> is not mentioned anywhere within the project:</p>
  
  <pre><code>$ grep -ri AppConstants .         # finds nothing
  $ find . | grep -i AppConstants   # finds nothing
  </code></pre>
  
  <p>This <code>AppConstants</code> exists in another project that mine depends on. I don't have the source code of that other project on my PC. My teammates can all reproduce this problem, it's not specific to my PC. Our pom hasn't changed recently, but we know the pom of the other team is changing a lot these days.</p>
  
  <p>There is one class in my project that uses <code>SomeOther</code> class from the other project. If I build using <code>-Dproject.build.sourceEncoding=Cp1252</code>, then the build works, and in my <code>target</code> folder I see <code>SomeOther.class</code>, <code>AppConstants.class</code>, and a few other clases from the other project generated. If I remove from my project the class that uses <code>SomeOther</code>, then I can build normally, though the project will not work, as it needs those other classes.</p>
  
  <blockquote>
    <p>@Gus: Knowing that it's in <code>SomeOther</code>, can you make a public-safe sample project that exhibits the same behavior? Failing that, describe the heirarchy, and where you're running <code>mvn compile</code> from... do you have a multi-module project, and you're building a subproject?</p>
  </blockquote>
  
  <p>Too hard to create a public-safe sample. My project is multi-module, when I run <code>mvn compile</code> at the top, it fails at a submodule, so for faster iteration I've been running in the submodule instead. The result is the same but faster. But you made me think: I will check if our builds generate <code>.class</code> files for other projects in other submodules.</p>
  
  <p><strong>Sharing code and the full pom</strong></p>
  
  <p>This is at work, so I cannot share complete code and pom, unfortunately. I can include anonymized snippets, if you ask for specific sections.</p>