2

我正在尝试遵循本指南:http ://maven.apache.org/plugins/maven-assembly-plugin/examples/multimodule/module-binary-inclusion-simple.html ,以便创建具有以下要求的项目结构(在所有建筑和包装之后):

Parent
      `child1
      |      `target/child1-1.0.jar
      `child2
      |      `target/child2-1.0.jar
      `child3
      |      `target/child3-1.0.jar
      `distribution
      |            `target/distribution-1.0-bin/child1/child1-1.0.jar
      |            `target/distribution-1.0-bin/child2/child2-1.0.jar
      |            `target/distribution-1.0-bin/child3/child3-1.0.jar
      `src
          `assemble/bin.xml

问题是:包装阶段之后;组装插件将所有target/distribution-1.0-bin/childN/目录展平为单个distribution目录;这使它看起来像这样:

       distribution
                   `target/distribution-1.0-bin/distribution/child1-1.0.jar
                   `target/distribution-1.0-bin/distribution/child2-1.0.jar
                   `target/distribution-1.0-bin/distribution/child3-1.0.jar

我如何防止这种扁平化?

我正在使用以下 shellscript 创建项目:

#!/bin/sh

# creating project root
mvn archetype:generate -D archetypeGroupId=org.codehaus.mojo.archetypes -D archetypeArtifactId=pom-root -D groupId=org.test -D artifactId=parent -D version=1.0 -D package=org.test -D interactiveMode=false
cd parent/

# creating child modules
for i in 1 2 3; do mvn archetype:generate -D archetypeGroupId=org.apache.maven.archetypes -D archetypeArtifactId=maven-archetype-quickstart -D groupId=org.test -D artifactId=child${i} -D version=1.0 -D package=org.test -D interactiveMode=false; done

# creating distribution module
mvn archetype:generate -D archetypeGroupId=org.codehaus.mojo.archetypes -D archetypeArtifactId=pom-root -D groupId=org.test -D artifactId=distribution -D version=1.0 -D package=org.test -D interactiveMode=false

# making dir for assemblies
mkdir src/assemble/ -p

; 我的 Parent/src/assemble/bin.xml 与上面提到的 url(程序集描述符部分)以及 Parent/pom.xml(POM 部分,片段 #1)和我的 Parent/distribution/完全没有变化。来自 POM 部分的 pom.xml 令牌,片段 #2 仅更改在和<plugins>之间添加缺少的标签。<build><plugin>

编辑1

好的,因为我两次被问及实际的 poms,所以在这里它们从url和 maven quicktype 原型移动到这个页面:

Parent/pom.xml

<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.test</groupId>
  <artifactId>parent</artifactId>
  <version>1.0</version>

  <packaging>pom</packaging>

  <name>Parent</name>

  <modules>
    <module>child1</module>
    <module>child2</module>
    <module>child3</module>
    <module>distribution</module>
  </modules>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.3</version>
          <configuration>
            <descriptors>
              <descriptor>src/assemble/bin.xml</descriptor>
            </descriptors>
          </configuration>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Parnet/child1/pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <artifactId>parent</artifactId>
    <groupId>org.test</groupId>
    <version>1.0</version>
  </parent>
  <groupId>org.test</groupId>
  <artifactId>child1</artifactId>
  <version>1.0</version>
  <name>child1</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

Parent/distribution/pom.xml

<?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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.test</groupId>
    <artifactId>parent</artifactId>
    <version>1.0</version>
  </parent>

  <artifactId>distribution</artifactId>

  <packaging>pom</packaging>

  <name>Distribution</name>

  <!-- NOTE: These dependency declarations are only required to sort this project to the 
       end of the line in the multimodule build. 

       Since we only include the child1 module in our assembly, we only need to ensure this
       distribution project builds AFTER that one...
  -->
  <dependencies>
    <dependency>
      <groupId>org.test</groupId>
      <artifactId>child1</artifactId>
      <version>1.0</version>
    </dependency>
  </dependencies>

  <build>
<plugins> <!-- exception -->
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <executions>
        <execution>
          <id>distro-assembly</id>
          <phase>package</phase>
          <goals>
            <goal>single</goal>
          </goals>
          <configuration>
            <descriptors>
              <descriptor>src/assemble/bin.xml</descriptor>
            </descriptors>
          </configuration>
        </execution>
      </executions>
    </plugin>
</plugins> <!-- exception -->
  </build>
</project>

编辑2

以及描述符文件:

Parent/src/assemble/bin.xml

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <id>bin</id>
  <formats>
    <format>dir</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>

      <!-- Enable access to all projects in the current multimodule build! -->
      <useAllReactorProjects>true</useAllReactorProjects>

      <!-- Now, select which projects to include in this module-set. -->
      <includes>
        <include>org.test:child1</include>
      </includes>
      <binaries>
        <outputDirectory>modules/${artifactId}</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>
4

0 回答 0