在多模块项目中:
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
说明:
pom
更改为jar
确实可以正常工作![错误]无法执行目标org.apache.maven.plugins:maven-assembly-plugin:2.6:项目父级上的单个(构建模块):创建程序集失败:创建程序集归档软件包时出错:您必须设置至少一个文件。 - > [帮助1]
(完整代码:https://github.com/gallardo/SO/tree/master/SO-33999969)
...
<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>
...
<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>
<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>
<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>
(模拟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>