模块:引用desciptor中的另一个模块

我的组件描述符(APP1)是:

  <?xml version="1.0" encoding="UTF-8"?>
  <assembly>
  <id>report</id>
    <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
    <include>*-APP2</include>[trying to refer to another module ie module-APP2]
      </includes>
      <sources>
    <fileSets>
      <fileSet>
        <directory>/</directory>
        <includes>
          <include>**/target</include>
        </includes>
      </fileSet>
    </fileSets>
    <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
    <outputDirectoryMapping>/</outputDirectoryMapping>
      </sources>
    </moduleSet>
  </moduleSets>
 </assembly>

当我运行mvn install cmd时,我正在接受

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '*-APP2'

我哪里错了?

我修改为:

<?xml version="1.0" encoding="UTF-8"?><assembly>
  <id>report</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
    <include>sampleMaven:module-APP2</include>
      </includes>
      <sources>
    <fileSets>
      <fileSet>
        <directory>/</directory>
        <includes>
          <include>target/*</include>
        </includes>
      </fileSet>
    </fileSets>
    <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
    <outputDirectoryMapping>/</outputDirectoryMapping>
      </sources>
    </moduleSet>
  </moduleSets>
</assembly>

仍然得到:

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'sampleMaven:module-APP2'

18 / sep上更新:Main proj pom.xml - >

http://maven.apache.org/maven-v4_0_0.xsd“> 4.0.0 sampleMaven anu 0.0.1-SNAPSHOT pom

APP1

<module>APP2</module>

2)对于APP1,pom.xml是 - >

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

anu sampleMaven 0.0.1-SNAPSHOT 4.0.0 sampleMaven APP1 APP1 0.0.1-SNAPSHOT pom
../APP2

<build>
 <plugins>
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-3</version>
    <executions>
    <execution>
      <id>assemblyone</id>
      <phase>compile</phase>
      <goals>
            <goal>single</goal>
      </goals>
      <configuration>
        <finalName>App1</finalName>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
          <descriptor>${basedir}/src/main/resources/assemblies/report.xml</descriptor>
        </descriptors>
      </configuration>
    </execution>
     </executions>
    </plugin>
  </plugins>
</build> 
</project> ...

3)程序集描述符是 - >

报告jar错误

 <sources>
  <fileSets>
    <fileSet>
      <directory>/</directory>
      <includes>
       <include>target/*</include>
      </includes>
    </fileSet>
  </fileSets>
  <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
  <outputDirectoryMapping>/</outputDirectoryMapping>
 </sources>
 <binaries>
   <outputDirectory>
      ${module.artifactId}-${module.version}
   </outputDirectory>
   <dependencySets>
      <dependencySet/>
   </dependencySets>
 </binaries>
</moduleSet>

在运行gettting - >错误stacktrace:

org.apache.maven.project.DuplicateProjectException:项目'sampleMaven:APP2'被复制到反应堆中


更新:Maven书籍有关于在程序集中包含moduleSets的章节。 您在示例中使用的方法已被弃用。 从父级定义moduleSets时,构建顺序也有问题。 必须首先构建父项,以便子项可以继承它,但必须构建子项以便父项可以在其组合中包含该项。 以下方法处理该周期。

定义一个引用汇编模块的父POM。

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>name.seller.rich</groupId>
  <artifactId>test-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <modules>
    <module>test-assembly</module>
  </modules>
  <dependencies>
</project>

在汇编模块中,定义一个具有相对于实际应用模块的相对路径的模块,并定义汇编插件配置:

<?xml version="1.0" encoding="UTF-8"?>
<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>name.seller.rich</groupId>
  <artifactId>test-assembly</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <modules>
    <module>../my-app2</module>
  </modules>
  <build>
    <plugins>
      <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-4</version>
    <executions>
      <execution>
        <id>assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <finalName>App1</finalName>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>src/main/assembly/my-assembly.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
      </plugin>
    </plugins>
  </build>
</project>

和my-assembly.xml的定义如下:

<?xml version="1.0" encoding="UTF-8"?><assembly>
  <id>my-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>  
    <moduleSet>
      <binaries>
        <outputDirectory>
          ${module.artifactId}-${module.version}
        </outputDirectory>
        <dependencySets>
          <dependencySet/>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

构建父模块将生成以下构建顺序:

  • 测试父
  • 我-APP 2
  • 测试组件
  • 所以当程序集打包时,my-app2就构建好了,并且可以包含它。 二进制文件声明将包括罐子。


    我仍然在寻找一个解决方案来构建一个多模块应用程序,并且我认为我快到了! :-)

    诀窍是构建一个独立的模块,不要将它添加到父级,因为您要构建父级(构建所有模块),然后调用该程序集。

    我得到了一个包含我需要的全部zip文件,只有可执行的jar文件不包含源代码......但我会尽量弄清楚。 如果我能使它工作,我会在这里粘贴解决方案:)

    和平

    链接地址: http://www.djcxy.com/p/29681.html

    上一篇: Module:referencing another module from the desciptor

    下一篇: Maven WAR dependency