Change maven dependency for artifact using classifier -


with maven jar plugin build 2 jar: bar-1.0.0.jar , bar-1.0.0-client.jar.

actually in pom have following dependency:

<dependency>       <groupid>de.app.test</groupid>    <artifactid>foo</artifactid>    <version>1.0.0</version> </dependency> 

this artifact exist in 2 version bar-1.0.0.jar , bar-1.0.0-client.jar

i want make bar-1.0.0-client.jar dependent of foo-1.0.0-client.jar , bar-1.0.0.jar dependent of foo-1.0.0.jar.

================

->first (wrong) solution: define scope provided , use right foo package when using bar.jar

->second (long) solution : add 'server' classifier other jar. use different profile build foo artifact , put classifier in property.

<dependency>     <groupid>de.app.test</groupid>     <artifactid>foo</artifactid>     <version>1.0.0</version>     <classifier>${profile.classifier}<classifier> </dependency> 

================
concerning profile solution.

interfaces module pom

<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">     <parent>         <groupid>com.app</groupid>         <artifactid>myapp-parent</artifactid>         <version>1.1.0</version>     </parent>     <modelversion>4.0.0</modelversion>     <groupid>com.app</groupid>     <artifactid>myapp-interfaces</artifactid>     <version>1.1.0-snapshot</version>     <packaging>jar</packaging>     <name>myapp interfaces</name>     <profiles>         <profile>             <id>server</id>             <activation>                 <activebydefault>true</activebydefault>             </activation>             <build>                 <plugins>                     <plugin>                         <artifactid>maven-jar-plugin</artifactid>                         <executions>                             <execution>                                 <id>jar-server</id>                                 <phase>package</phase>                                 <goals>                                     <goal>jar</goal>                                 </goals>                                 <configuration>                                     <classifier>server</classifier>                                 </configuration>                             </execution>                         </executions>                     </plugin>                 </plugins>             </build>         </profile>         <profile>             <id>client</id>             <activation>                 <activebydefault>true</activebydefault>             </activation>             <build>                 <plugins>                     <plugin>                         <artifactid>maven-jar-plugin</artifactid>                         <executions>                             <execution>                                 <id>jar-client</id>                                 <phase>package</phase>                                 <goals>                                     <goal>jar</goal>                                 </goals>                                 <configuration>                                     <classifier>client</classifier>                                     <excludes>                                         <exclude>**/server/**</exclude>                                     </excludes>                                 </configuration>                             </execution>                         </executions>                     </plugin>                 </plugins>             </build>         </profile>     </profiles> </project> 

implementation module pom

<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">     <parent>         <groupid>com.app</groupid>         <artifactid>myapp-parent</artifactid>         <version>1.1.0-snapshot</version>     </parent>     <modelversion>4.0.0</modelversion>     <groupid>com.app</groupid>     <artifactid>myapp-model</artifactid>     <version>1.1.0-snapshot</version>     <packaging>jar</packaging>     <name>myapp model</name>     <properties>         <myapp-interfaces.classifier></myapp-interfaces.classifier>         <myapp-interfaces.version>1.1.0-snapshot</myapp-interfaces.version>      </properties>     <dependencies>         <dependency>             <groupid>com.app</groupid>             <artifactid>myapp-interfaces</artifactid>             <version>${myapp-interfaces.version}</version>             <classifier>${myapp-interfaces.classifier}</classifier>         </dependency>         [...]     </dependencies>     <profiles>         <profile>             <id>server</id>             <build>                 <plugins>                     <plugin>                         <artifactid>maven-jar-plugin</artifactid>                         <executions>                             <execution>                                 <id>jar-server</id>                                 <phase>package</phase>                                 <goals>                                     <goal>jar</goal>                                 </goals>                                 <configuration>                                     <classifier>server</classifier>                                 </configuration>                             </execution>                         </executions>                     </plugin>                 </plugins>             </build>             <dependencies>                 <dependency>                     <groupid>com.app</groupid>                     <artifactid>myapp-interfaces</artifactid>                     <version>${myapp-interfaces.version}</version>                     <classifier>${myapp-interfaces.classifier}</classifier>                 </dependency>             </dependencies>             <properties>                 <myapp-interfaces.classifier>server</myapp-interfaces.classifier>             </properties>         </profile>         <profile>             <id>client</id>             <build>                 <plugins>                     <plugin>                         <artifactid>maven-jar-plugin</artifactid>                         <executions>                             <execution>                                 <id>jar-client</id>                                 <phase>package</phase>                                 <goals>                                     <goal>jar</goal>                                 </goals>                                 <configuration>                                     <classifier>client</classifier>                                     <excludes>                                         <exclude>**/server/**</exclude>                                         <exclude>**/meta-inf/services/**</exclude>                                     </excludes>                                 </configuration>                             </execution>                         </executions>                     </plugin>                 </plugins>             </build>             <properties>                 <myapp-interfaces.classifier>client</myapp-interfaces.classifier>             </properties>             <dependencies>                 <dependency>                     <groupid>com.app</groupid>                     <artifactid>myapp-interfaces</artifactid>                     <version>${myapp-interfaces.version}</version>                     <classifier>${myapp-interfaces.classifier}</classifier>                 </dependency>             </dependencies>         </profile>     </profiles> </project> 

the problem solution due fact client interface have missing interfaces , maven throw compilation error during compile phase.

and if use myapp-model , other project didn't not have dependency right myapp-interface.

i wonder if it's possible build jar , put specific pom inside ?

for interfaces.

i change nothing , build both interfaces.jar (client + server).

for model import both jar optional

<dependency>         <groupid>com.app</groupid>         <artifactid>myapp-interfaces</artifactid>         <version>${myapp-interfaces.version}</version>         <classifier>client</classifier>         <optional>true</optional>     </dependency>     <dependency>         <groupid>com.app</groupid>         <artifactid>myapp-interfaces</artifactid>         <version>${myapp-interfaces.version}</version>         <classifier>server</classifier>         <optional>true</optional>     </dependency> 

with can build both model's version without error.

in client application , server application

for each application create dependency right interfaces.jar , models.jar


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -