What is a POM?
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is?target
; the source directory, which is?src/main/java
; the test source directory, which is?src/test/java
; and so on. When executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.
Some of the configuration that can be specified in the POM are the project dependencies, the plugins or goals that can be executed, the build profiles, and so on. Other information such as the project version, description, developers, mailing lists and such can also be specified.
聚合
Maven 的聚合其實就是項目與子項目的表示,其存在的意義在于快速構(gòu)建項目。例如我們有一個淘寶商城項目,這個項目有賬號子項目和郵件子項目。在這個時候我們需要在 Maven 中表達這種項目歸屬關(guān)系,那么我們就可以用 Maven 的聚合來進行配置。
繼承
Maven 的繼承是為了消除重復(fù)配置而存在的。例如我們的 account 子模塊和 mail 子模塊都需要 junit-test 依賴,但是都得在自己的模塊里都寫一次,這樣豈不是會造成代碼的重復(fù)。這個時候就可以將共同的依賴寫在父類模塊中,讓子類繼承這些依賴。
聚合與繼承的關(guān)系
從上面可以看到多模塊 Maven 項目中的聚合與繼承其實是兩個概念,其目的是完全不同的。聚合是為了方便快速構(gòu)建項目,繼承是為了消除重復(fù)配置。
對于聚合模塊來說,它知道哪些被聚合的模塊(通過modules元素),但那些被聚合的模塊不知道這個聚合模塊的存在。
對于繼承關(guān)系的父 POM 來說,它不知道哪些子模塊繼承于它,但那些子模塊都必須知道自己的父 POM 是什么。文章來源:http://www.zghlxwxcb.cn/news/detail-492914.html
Maven – Introduction to the POM文章來源地址http://www.zghlxwxcb.cn/news/detail-492914.html
到了這里,關(guān)于Maven 聚合和繼承 Inheritance vs Aggregation的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!