Mit dem maven jar plugin erstelle ich zwei jar: bar-1.0.0.jar und bar-1.0.0-client.jar.Ändere die maven-Abhängigkeit für Artefakte mit dem Klassifikator
Eigentlich ich in meinem POM hat folgende Abhängigkeit:
<dependency>
<groupId>de.app.test</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
</dependency>
Dieser Artefakt gibt es auch in zwei Version Bar-1.0.0.jar und Bar-1.0.0-client.jar
Ich möchte bar-1.0.0-client.jar abhängig von foo-1.0.0-client.jar und bar-1.0.0.jar abhängig von foo-1.0.0.jar machen.
================
-> First (falsch) Lösung: den Umfang definieren, wie die richtige foo Paket zur Verfügung gestellt und verwendet werden bei der Verwendung von bar.jar
-> Zweite (lange) Lösung: Fügen Sie dem anderen Jar den Server-Klassifikator hinzu. Verwenden Sie ein anderes Profil, um das Foo-Artefakt zu erstellen, und fügen Sie den Klassifikator in eine Eigenschaft ein.
<dependency>
<groupId>de.app.test</groupId>
<artifactId>foo</artifactId>
<version>1.0.0</version>
<classifier>${profile.classifier}<classifier>
</dependency>
================
bezüglich der Profillösung.
Schnittstellen-Modul 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>
Einführungsmodul 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>
Das Problem bei dieser Lösung ist aufgrund der Tatsache, dass meine Client-Schnittstelle haben einige fehlende Schnittstellen und Maven einen Kompilierungsfehler werfen während die Kompilierphase.
Und wenn ich myapp-model und ein anderes Projekt verwende, habe ich keine Abhängigkeit zur richtigen myapp-Schnittstelle.
Ich frage mich, ob es möglich ist, ein Glas zu bauen und ein bestimmtes Pom innen zu setzen?
Die lange Lösung ist richtig. Also, was ist die Frage? –
In der Tat hat es nicht funktioniert. Weil ich in meinem foo-server und foo-client nicht die ein paar schnittstellen entfernt habe. Wenn ich das Projekt erstelle, sehe ich mich einem Kompilierungsfehler gegenüber. Ich werde meine Frage bearbeiten, um dieses Problem zu erklären. – Vlagorce
Eine alte Frage zum selben Thema [1]: http: //www.mail-archive.com/[email protected]/msg102761.html – Vlagorce