我在一個多模塊的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