Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This can be done without profiles if you specify multiple plugin executions and <a href="http://maven.apache.org/guides/getting-started/index.html#How_do_I_filter_resource_files" rel="noreferrer">resource filtering</a>.</p> <p>Create a properties file for each version in <code>${basedir}/src/main/filters</code> (e.g. prod.properties, dev.properties) holding appropriate values for each environment.</p> <p>Turn on filtering for your resources: </p> <pre class="lang-xml prettyprint-override"><code>&lt;resources&gt; &lt;resource&gt; &lt;directory&gt;src/main/resources&lt;/directory&gt; &lt;filtering&gt;true&lt;/filtering&gt; &lt;/resource&gt; &lt;/resources&gt; </code></pre> <p>Now add the resource plugin executions. Note the different filter file and output directory.</p> <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-resources-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;default-resources&lt;/id&gt; &lt;phase&gt;process-resources&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;resources&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;outputDirectory&gt;${project.build.outputDirectory}/dev&lt;/outputDirectory&gt; &lt;filters&gt; &lt;filter&gt;${basedir}/src/main/filters/dev.properties&lt;/filter&gt; &lt;/filters&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;execution&gt; &lt;id&gt;prod&lt;/id&gt; &lt;phase&gt;process-resources&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;resources&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;outputDirectory&gt;${project.build.outputDirectory}/prod&lt;/outputDirectory&gt; &lt;filters&gt; &lt;filter&gt;${basedir}/src/main/filters/prod.properties&lt;/filter&gt; &lt;/filters&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>Finally, the jar plugin; note classifier and input directory:</p> <pre class="lang-xml prettyprint-override"><code>&lt;plugin&gt; &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt; &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;default-jar&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;jar&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;classifier&gt;dev&lt;/classifier&gt; &lt;classesDirectory&gt;${project.build.outputDirectory}/dev&lt;/classesDirectory&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;execution&gt; &lt;id&gt;jar-prod&lt;/id&gt; &lt;phase&gt;package&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;jar&lt;/goal&gt; &lt;/goals&gt; &lt;configuration&gt; &lt;classifier&gt;prod&lt;/classifier&gt; &lt;classesDirectory&gt;${project.build.outputDirectory}/prod&lt;/classesDirectory&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre> <p>Running <code>mvn clean install</code> should produce the properly filtered resources in artifacts with <code>dev</code> and <code>prod</code> classifiers like you want.</p> <p>In the example, I used execution IDs of <code>default-resources</code> and <code>default-jar</code> for the dev versions. Without this you would also get an unclassified jar artifact when you build.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload