إدارة التبعيات متعددة الوحدات النمطية مع البرنامج المساعد الجمعية في مافن

StackOverflow https://stackoverflow.com/questions/9033920

سؤال

يمكنني استخدام البرنامج المساعد Assembly MaVen لإنشاء مجموعة لمشروعي متعدد الوحدات النمطية. هناك تطبيقان منفصلان تم إنشاؤه من مشروع متعدد الوحدات النمطية، كل منها مجموعة منفصلة من التبعيات. قمت بإجراء واصف تجميع مخصص يقوم بتجميع دليلين (لكل تطبيق) مع بناء الوحدة والتبعية الخاصة بكل منها. إنه كل شيء على ما يرام ولكن شيء واحد - يضع تبعيات لكلا الوحدات إلى جمعية بعضهم البعض.

فيما يلي نسخة مبسطة من مشروعي، والتي لها نفس السلوك بالضبط.

النظر في مشروع يتكون من وحدتي وحدود التجميع: giveacodicetagpre.

لقد أضافت التبعيات بحتة للمظاهرة: giveacodicetagpre.

إليك الوالد بوم: giveacodicetagpre.

module1 pom: giveacodicetagpre.

module2 بوم: giveacodicetagpre.

التجميع بوم: giveacodicetagpre.

وأخيرا، واصف التجميع: giveacodicetagpre.

كما ترون، يتم ربط التجميع بمرحلة الحزمة. لذلك، عندما أعمل giveacodicetagpre.

من الدليل الأصل، لدي التجمع التالي giveacodicetagpre.

أساسا، المشكلة هنا هي أن الوحدة 1 لا تعتمد على المشجعين المشاعون، لكن البرنامج المساعد الجمعية شمل الاعتماد. وبالمثل، مع Module2 و Commons CLI.

هل يمكن لشخص ما يفسر لماذا يتصرف البرنامج المساعد الجمعية بهذه الطريقة؟

ماذا سيكون حلا؟

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

المحلول

I've always had similar experiences using the assembly plugin with multi-module projects where the end result wasn't what I expected. I hope someone else can provide a more accurate answer as to why that's happening and how best to use those two concepts in tandem.

That said, a possible work-around would be to have module1 and module2 generate their own assembly artifacts which contain their respective jars and dependencies. Then you can modify the assembly sub-module pom file to have dependencies on the generated distribution artifacts from its sibling modules and then unpack those into a new assembly.

In both Module1 and Module2's pom files you can add an assembly plugin configuration to your package phase much like you did with the assembly sub-module.

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2.2</version>

        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>

        <configuration>
          <descriptors>
            <descriptor>src/main/assembly/descriptor.xml</descriptor>
          </descriptors>
        </configuration>
      </plugin>
    </plugins>
  </build>

Module1 would have a src/main/assembly/descriptor.xml like this

<assembly>
  <id>distribution</id>
  <includeBaseDirectory>false</includeBaseDirectory>

  <formats>
    <format>zip</format>
  </formats>

  <dependencySets>
    <dependencySet>
      <outputDirectory>module1</outputDirectory>
      <unpack>false</unpack>
    </dependencySet>
  </dependencySets>
</assembly>

And Module2 will have a similar src/main/assembly/descriptor.xml

<assembly>
  <id>distribution</id>
  <includeBaseDirectory>false</includeBaseDirectory>

  <formats>
    <format>zip</format>
  </formats>

  <dependencySets>
    <dependencySet>
      <outputDirectory>module2</outputDirectory>
      <unpack>false</unpack>
    </dependencySet>
  </dependencySets>
</assembly>

Then in the assembly/pom.xml you would add the Module 1 and 2 zip artifacts as dependencies

  <dependencies>
    <dependency>
      <groupId>com.test.app</groupId>
      <artifactId>module1</artifactId>
      <version>1.0</version>
      <type>zip</type>
      <classifier>distribution</classifier>
    </dependency>
    <dependency>
      <groupId>com.test.app</groupId>
      <artifactId>module2</artifactId>
      <version>1.0</version>
      <type>zip</type>
      <classifier>distribution</classifier>
    </dependency>
  </dependencies>

...and trim up the assembly/src/main/assembly/descriptor.xml file to look like this

<assembly>
  <id>distribution</id>
  <includeBaseDirectory>false</includeBaseDirectory>

  <formats>
    <format>dir</format>
  </formats>

  <dependencySets>
    <dependencySet>
      <useTransitiveDependencies>false</useTransitiveDependencies>
      <unpack>true</unpack>
    </dependencySet>
  </dependencySets>

</assembly>

Like I said this would be one possible work around and unfortunately adds a significant amount of additional XML configuration to your build process. But it works.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top