Note that there are some explanatory texts on larger screens.

plurals
  1. POChange maven dependency for artifact using classifier
    text
    copied!<p>With the maven jar plugin I build two jar: bar-1.0.0.jar and bar-1.0.0-client.jar.</p> <p>Actually in my POM I have the following dependency:</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;de.app.test&lt;/groupId&gt; &lt;artifactId&gt;foo&lt;/artifactId&gt; &lt;version&gt;1.0.0&lt;/version&gt; &lt;/dependency&gt; </code></pre> <p>This artifact exist also in two version bar-1.0.0.jar and bar-1.0.0-client.jar</p> <p><strong>I want to make bar-1.0.0-client.jar dependent of foo-1.0.0-client.jar and bar-1.0.0.jar dependent of foo-1.0.0.jar</strong>.</p> <p>================</p> <p>->First (wrong) solution: define the scope as provided and use the right foo package when using bar.jar</p> <p>->Second (long) solution : Add 'server' classifier to the other jar. Use different profile to build the foo artifact and put the classifier in a property.</p> <pre><code>&lt;dependency&gt; &lt;groupId&gt;de.app.test&lt;/groupId&gt; &lt;artifactId&gt;foo&lt;/artifactId&gt; &lt;version&gt;1.0.0&lt;/version&gt; &lt;classifier&gt;${profile.classifier}&lt;classifier&gt; &lt;/dependency&gt; </code></pre> <p>================<br> <strong>Concerning the profile solution</strong>.<br></p> <p>Interfaces module pom</p> <pre><code>&lt;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"&gt; &lt;parent&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-parent&lt;/artifactId&gt; &lt;version&gt;1.1.0&lt;/version&gt; &lt;/parent&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-interfaces&lt;/artifactId&gt; &lt;version&gt;1.1.0-SNAPSHOT&lt;/version&gt; &lt;packaging&gt;jar&lt;/packaging&gt; &lt;name&gt;myapp Interfaces&lt;/name&gt; &lt;profiles&gt; &lt;profile&gt; &lt;id&gt;server&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;jar-server&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;server&lt;/classifier&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;profile&gt; &lt;id&gt;client&lt;/id&gt; &lt;activation&gt; &lt;activeByDefault&gt;true&lt;/activeByDefault&gt; &lt;/activation&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;jar-client&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;client&lt;/classifier&gt; &lt;excludes&gt; &lt;exclude&gt;**/server/**&lt;/exclude&gt; &lt;/excludes&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;/project&gt; </code></pre> <p>Implementation module pom</p> <pre><code>&lt;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"&gt; &lt;parent&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-parent&lt;/artifactId&gt; &lt;version&gt;1.1.0-SNAPSHOT&lt;/version&gt; &lt;/parent&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-model&lt;/artifactId&gt; &lt;version&gt;1.1.0-SNAPSHOT&lt;/version&gt; &lt;packaging&gt;jar&lt;/packaging&gt; &lt;name&gt;myapp Model&lt;/name&gt; &lt;properties&gt; &lt;myapp-interfaces.classifier&gt;&lt;/myapp-interfaces.classifier&gt; &lt;myapp-interfaces.version&gt;1.1.0-SNAPSHOT&lt;/myapp-interfaces.version&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-interfaces&lt;/artifactId&gt; &lt;version&gt;${myapp-interfaces.version}&lt;/version&gt; &lt;classifier&gt;${myapp-interfaces.classifier}&lt;/classifier&gt; &lt;/dependency&gt; [...] &lt;/dependencies&gt; &lt;profiles&gt; &lt;profile&gt; &lt;id&gt;server&lt;/id&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;jar-server&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;server&lt;/classifier&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-interfaces&lt;/artifactId&gt; &lt;version&gt;${myapp-interfaces.version}&lt;/version&gt; &lt;classifier&gt;${myapp-interfaces.classifier}&lt;/classifier&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;properties&gt; &lt;myapp-interfaces.classifier&gt;server&lt;/myapp-interfaces.classifier&gt; &lt;/properties&gt; &lt;/profile&gt; &lt;profile&gt; &lt;id&gt;client&lt;/id&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;jar-client&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;client&lt;/classifier&gt; &lt;excludes&gt; &lt;exclude&gt;**/server/**&lt;/exclude&gt; &lt;exclude&gt;**/META-INF/services/**&lt;/exclude&gt; &lt;/excludes&gt; &lt;/configuration&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;properties&gt; &lt;myapp-interfaces.classifier&gt;client&lt;/myapp-interfaces.classifier&gt; &lt;/properties&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;com.app&lt;/groupId&gt; &lt;artifactId&gt;myapp-interfaces&lt;/artifactId&gt; &lt;version&gt;${myapp-interfaces.version}&lt;/version&gt; &lt;classifier&gt;${myapp-interfaces.classifier}&lt;/classifier&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;/project&gt; </code></pre> <p>The problem with this solution is due to the fact that my client interface have some missing interfaces and maven throw a compilation error during the compile phase.</p> <p>And if I use myapp-model and an other project I didn't not have dependency to the right myapp-interface.</p> <p>I wonder if it's possible to build a jar and put a specific pom inside ?</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