父模块中的程序集插件可以使用`moduleSets`聚合pom子元素的二进制工件吗?

时间:2015-11-30 13:39:04

标签: maven

在多模块项目中:

parent
  |- child1 (packaging:pom)

可以parent汇总由child1生成的工件吗?

经过两天以上的测试和阅读文档后,我不确定这是不可能的设计,错误或我自己没有找到明显的。

使用:

$mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)
Maven home: /usr/share/maven-bin-3.0
Java version: 1.8.0_66, vendor: Oracle Corporation

说明:

  • 在以下示例中,将child1打包从pom更改为jar确实可以正常工作!
  • 当前错误:
  

[错误]无法执行目标org.apache.maven.plugins:maven-assembly-plugin:2.6:项目父级上的单个(构建模块):创建程序集失败:创建程序集归档软件包时出错:您必须设置至少一个文件。 - > [帮助1]

  • 我附加了第二版的child1的pom,这也没有用,我已经设置了所有jar包装绑定不适用于pom包装模块,也就是说,它是&#39 ;用于包装的有效poms = pom或包装= jar是相同的。这也不起作用!

示例代码

(完整代码:https://github.com/gallardo/SO/tree/master/SO-33999969

parent pom:/pom.xml

...
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<name>parent</name>

<modules>
    <module>child1</module>
</modules>

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/bundle.xml</descriptor>
                </descriptors>
                <attach>false</attach>
            </configuration>
            <executions>
                <execution>
                    <id>build-module</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>          
    </plugins>
</build>

child1 pom:child1 / pom.xml

...
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<name>child1</name>
<build>
    <plugins>
        <!-- Assembly -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/module.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>build-module</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>          
    </plugins>    
</build>

父程序集:/src/assembly/bundle.xml

<assembly ... >
    <id>bundle</id>
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>

    <moduleSets>
        <moduleSet>
            <useAllReactorProjects>false</useAllReactorProjects>
            <includeSubModules>true</includeSubModules>

            <binaries>
                <attachmentClassifier>module</attachmentClassifier>
                <includeDependencies>false</includeDependencies>
                <outputDirectory>my/output/directory</outputDirectory>
                <unpack>false</unpack>
            </binaries>
        </moduleSet>
    </moduleSets>
</assembly>

child1程序集:src / assembly / module.xml

<assembly ...>
    <id>module</id>
    <formats>
        <format>zip</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/java</directory>
            <outputDirectory>module-${project.artifactId}/java</outputDirectory>
            <filtered>false</filtered>
        </fileSet>
        <fileSet>
            <directory>${project.build.directory}</directory>
            <outputDirectory>module-${project.artifactId}/lib</outputDirectory>
            <includes>
                <include>${project.build.finalName}.jar</include>
            </includes>
        </fileSet>
    </fileSets>

</assembly>

child1&#39;扩展&#39; pom:/child1/pom.xml

(模拟jar包装)

...
<artifactId>child1</artifactId>
<packaging>jar</packaging>
<name>child1</name>
<build>
    <plugins>
        <!--
        These plugin settings are the plugin bindings that jar packaging
        configures for the jar packaging.
        If this project has packaging = pom, enabling them results in an
        effective pom identical to packaging = jar.
        -->            
        <plugin>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.5</version>
            <executions>
                <execution>
                    <id>default-testResources</id>
                    <phase>process-test-resources</phase>
                    <goals>
                        <goal>testResources</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-resources</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>resources</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.3.2</version>
            <executions>
                <execution>
                    <id>default-jar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <executions>
                <execution>
                    <id>default-compile</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
                <execution>
                    <id>default-testCompile</id>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>testCompile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.10</version>
            <executions>
                <execution>
                    <id>default-test</id>
                    <phase>test</phase>
                    <goals>
                        <goal>test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <!-- Assembly -->
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/module.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>build-module</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>          
    </plugins>    
</build>

0 个答案:

没有答案