我认为你所描述的是可能的。首先,创建一个父POM,在其中在<dependencyManagement>
元素中声明依赖项:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupIdA<groupId>
<artifactId>parent</artifactId>
<packaging>pom<packaging>
<version>1-SNAPSHOT</version>
...
<dependencyManagement>
<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>
为了创建项目的汇编,触发 package 阶段:
mvn package
而这将在目标目录中生成以下汇编:
target/child-1.0-SNAPSHOT-jar-with-dependencies.jar
我不确定你想用这个程序集来做什么(在门户项目中使用它作为依赖项还是从父POM中拉取依赖项?只是简化Liferay部署吗?)。不过所有选项都是可能的。
请参考Maven Assembly插件文档以获取更多详细信息。