解決Maven子模塊之間相互引用


 將A、B、C代碼合並模塊D,我們把它當做一個輔助構建模塊,然后讓A、B、C模塊都依賴於D模塊,這樣的話就可以成功編譯A、B和C模塊

 

要想把A、B、C三個模塊整合在一起編譯,需要借助build-helper-maven-plugin插件,這個插件在Maven構建周期提供一些輔助功能,下面列出插件的提供的功能列表:

  • build-helper:add-source:添加更多的構建源碼目錄

  • build-helper:add-test-source:添加更多的測試源碼目錄

  • build-helper:add-resource:添加更多的資源目錄

  • build-helper:add-test-resource:添加更多的測試資源目錄

  • build-helper:attach-artifact:在安裝和部署周期附加artifacts

  • build-helper:maven-version:添加一個指定當前Maven版本的屬性

  • build-helper:parse-version:添加一個指定組件版本的屬性

  • build-helper:released-version:決定當前項目的最終版本

  • build-helper:remove-project-artifact:從本地資源庫中移除項目的artifacts

  • build-helper:reserve-network-port:Reserve a list of random and unused network ports.

在這里我們要用到build-helper:add-source這個功能,將模塊A、B、C的源碼路徑加進來。

我們再添加一個輔助模塊D,在輔助模塊D中使用build-helper-maven-plugin插件,然后讓模塊A、B、C都依賴於輔助模塊D

 

<properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <module.a.src>../../module/module-A/src/main/java</module.a.src>
         <module.b.src>../../module/module-B/src/main/java</module.b.src>
         <module.c.src>../../module/module-C/src/main/java</module.c.src>
   </properties>
    <build>
         <plugins>
                 <!-- 解決模塊相互依賴,綜合所有相互依賴代碼統一編譯 -->
                 <plugin>
                         <groupId>org.codehaus.mojo</groupId>
                         <artifactId>build-helper-maven-plugin</artifactId>
                         <executions>
                                 <execution>
                                         <id>add-source</id>
                                         <phase>generate-sources</phase>
                                         <goals>
                                                 <goal>add-source</goal>
                                         </goals>
                                         <configuration>
                                                 <sources>
                                                         <source>${module.a.src}</source>
                                                         <source>${module.b.src}</source>
                                                         <source>${module.c.src}</source>
                                                 </sources>
                                         </configuration>
                                 </execution>
                         </executions>
                 </plugin>
         </plugins>
   </build>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM