Excluding Mock Datasource In Maven Profile
<p>I have a java backend project that includes services to import data from a database. While working on new features, I sometimes need to deploy and run the code on my local machine. Since I don't actually want to connect to the production db while running experimental code, I set up a mock datasource class using Mockito.</p>

<p>The Mock datasource works fine and does what I want when running locally. The problem I'm running into is that I don't want to include that class and its associated dependencies when doing a production deployment. I added an <code>&lt;excludes&gt;</code> section to the configuration section of maven-compiler-plugin. I added the Mock specific dependencies to a 'local' profile section. When I actually try to do a compile using maven however, I get compile errors on the mock datasource class that was supposed to be excluded. I'll post the relevant snippets from my .pom file below. I've tried putting the excludes statement in a specific profile and in the 'default' as shown below. Any help with the would be greatly appreciated.</p>

<pre><code>&lt;profiles&gt;
    &lt;profile&gt;
        &lt;id&gt;local&lt;/id&gt;
        &lt;properties&gt;
        &lt;config&gt;config.dev.properties&lt;/config&gt;
        &lt;/properties&gt;

        &lt;dependencies&gt;          
            &lt;dependency&gt;
                &lt;groupId&gt;org.mockito&lt;/groupId&gt;
                &lt;artifactId&gt;mockito-core&lt;/artifactId&gt;
                &lt;version&gt;1.9.5&lt;/version&gt;            
            &lt;/dependency&gt;
        &lt;/dependencies&gt;
    &lt;/profile&gt;
    ...
 &lt;/profiles&gt;


&lt;build&gt;
    &lt;finalName&gt;order&lt;/finalName&gt;
    &lt;plugins&gt;
      &lt;plugin&gt;
            &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
            &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
            &lt;version&gt;3.1&lt;/version&gt;

            &lt;configuration&gt;

                &lt;excludes&gt;
                       &lt;exclude&gt;com/tura/order/guice/mock/**&lt;/exclude&gt;
                 &lt;/excludes&gt;
                 &lt;compilerId&gt;groovy-eclipse-compiler&lt;/compilerId&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;

    &lt;/plugins&gt;
 &lt;/build&gt;
</code></pre>