使用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.0.JAR依赖Foo-1.0.0.jar.

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

- >第一个(错误)解决方案:使用bar.jar时定义提供的范围并使用正确的foo软件包

- >第二(长)解决方案:将“服务器”分类器添加到另一个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模型和另一个项目,我对正确的MyApp-Interface并不依赖。

我想知道是否可以建造一个罐子并将特定的POM放入其中?

有帮助吗?

解决方案

对于接口。

我什么都不更改并构建两个接口。JAR(客户端 +服务器)。

对于模型我将两个罐子作为可选

<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>

这样我就可以构建两个模型的版本而不会出错。

在我的客户端应用程序和服务器应用程序中

对于每个应用程序,我创建对正确界面的依赖性。jar和models.jar

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top