سؤال

مع مكون Maven Jar Plugin I Build اثنين من الجرة: BAR-1.0.0.JAR و BAR-1.0.0-CLIENT.JAR.

في الواقع في بوم ، لدي التبعية التالية:

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

هذه القطع الأثرية موجودة أيضًا في إصدار اثنين

أريد أن أجعل BAR-1.0.0-client.jar اعتمادًا على FOO-1.0.0-LIANT.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 الصحيح.

أتساءل عما إذا كان من الممكن بناء جرة ووضع بوم محدد في الداخل؟

هل كانت مفيدة؟

المحلول

للواجهات.

لا أغير شيئًا وأبني كلا الواجهات.

للنموذجأنا استيراد كلاهما اختياري

<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