我在一个多模块的Maven项目正在与这些模块如何告诉maven程序集在子模块上只包含这个模块需要的依赖关系?
parent
|-- restful // this is a jersey restful service as a WAR
|-- shared // some stuff shared by all other modules as a jar
|-- cl-client // a commandline client to the restful service, needs assembly
父pom.xml中使用dependencyManagement列出所有模块使用的所有依赖
为CL-客户端的聚甲醛包括装配插件,用于在封装阶段执行:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>distro-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
和assembly.xml如下:
<assembly>
<id>commandlinable</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<moduleSets>
<moduleSet>
<useAllReactorProjects>true</useAllReactorProjects>
<includes>
<include>my:cl-client</include>
</includes>
<binaries>
<outputDirectory>${artifactId}</outputDirectory>
<unpack>true</unpack>
<dependencySets>
<dependencySet>
<outputDirectory>${artifactId}/lib</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>false</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
</moduleSets>
</assembly>
当我运行mvn package
时,cl-client模块组装得很好,确实创建了我所希望的目录,但唯一的问题是所有依赖关系jar都被复制到lib /目录中,即使那些仅用于通过诸如泽西相关罐子之类的“宁静”模块。我试图翻转useProjectArtifact
国旗,但它似乎没有任何区别。
所以我只是想知道如果有反正我可以告诉Maven程序集只包含cl-client模块所需的jar。我在多模块项目上的Maven汇编中搜集了不少在线资源,但无法得到任何明确的答案。
cl-client项目是否将restful项目作为依赖项?如果是这样,大概在cl-client项目上执行'mvn dependency:tree'会显示您在程序集输出中看到的所有JAR? –
'cl-client' pom是否从父pom继承? –
@Andrew是的,cl-client pom继承了父pom – Jim