Изменить зависимость maven для артефакта с помощью классификатора

С помощью плагина maven jar я создаю два jar: bar-1.0.0.jar и bar- 1.0.0-client.jar.

На самом деле в моем POM у меня есть следующая зависимость:

<dependency>   
   <groupId>de.app.test</groupId>
   <artifactId>foo</artifactId>
   <version>1.0.0</version>
</dependency>

Этот артефакт существует также в двух версиях bar-1.0.0.jar и bar-1.0.0-client.jar

Я хочу сделать bar-1.0 .0-client.jar зависит от foo-1.0.0-client.jar и bar-1.0.0.jar зависит от foo-1.0.0.jar .

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

-> Первое (неправильное) решение: определите предоставленную область и используйте правильный пакет foo при использовании bar.jar

- > Второе (долгое) решение: добавить классификатор «сервер» в другую банку. Используйте другой профиль, чтобы создать артефакт foo и поместить классификатор в свойство.

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

================
По поводу профильного решения .

Модуль интерфейсов 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>

Модуль реализации 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>

Проблема с этим решением связана с тем, что в моем клиентском интерфейсе отсутствуют некоторые интерфейсы, и maven выдает ошибку компиляции на этапе компиляции.

И если я использую myapp-model и другой проект, у меня не будет зависимости от правильного интерфейса myapp.

Интересно, можно ли построить банку и поместить внутрь особый помпон?

10
задан Vlagorce 3 December 2010 в 09:27
поделиться