我认为你所描述的是可能的。首先,创建一个父 POM,在 <dependencyManagement> 元素中声明依赖项:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupIdA<groupId>
<artifactId>parent</artifactId>
<packaging>pom<packaging>
<version>1-SNAPSHOT</version>
...
<dependencyManagement>
<!-- Standard dependencies used in several build modules. Ensures all modules
use the same version for these dependencies -->
<dependencies>
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>3.0.M1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
...
</dependencies>
<dependencyManagement>
...
</project>
然后,在一个子项目中,声明你需要的依赖而不声明它们的版本:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>parent</artifactId>
<groupId>groupIdA</groupId>
<version>1-SNAPSHOT</version>
</parent>
<artifactId>childB</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
...
</dependencies>
...
</project>
最后,使用默认的jar-with-dependencies 预定义程序集描述符来创建一个二进制包的通用程序集,其中所有依赖库都包含在存档中解包。
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- append to the packaging phase. -->
<goals>
<goal>single</goal> <!-- goals == mojos -->
</goals>
</execution>
</executions>
</plugin>
[...]
</plugins>
</build>
</project>
要创建项目程序集,请触发包阶段:
mvn package
这将在目标目录中生成以下程序集:
target/child-1.0-SNAPSHOT-jar-with-dependencies.jar
我只是不确定你想用这个程序集做什么(将它用作 portlet 项目中的依赖项与从父 POM 中提取依赖项?仅简化 liferay 部署?)。不过,所有选项都是可能的。
有关详细信息,请参阅Maven Assembly plugin 文档。