依赖管理和Maven
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                依赖管理和Maven
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                Maven偉大而成熟。 幾乎所有事物都總有解決方案。 您可能在組織項目上遇到的主要情況是依賴管理。 而不是每個項目都沒有自己的依賴關系,您需要一種集中化的方式來繼承那些依賴關系。
在這種情況下,您可以在父舞會上聲明托管依賴項。 在我的示例中,我只想包含Akka流依賴項。
<? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = " http://maven.apache.org/POM/4.0.0 " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation = " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd " > < modelVersion >4.0.0</ modelVersion > < groupId >org.example</ groupId > < artifactId >maven-dependency-management</ artifactId > < packaging >pom</ packaging > < version >1.0-SNAPSHOT</ version > < properties > < akka.version >2.5.31</ akka.version > < akka.http.version >10.1.11</ akka.http.version > < scala.binary.version >2.12</ scala.binary.version > </ properties > < modules > < module >child-one</ module > </ modules > < dependencyManagement > < dependencies > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-stream_2.12</ artifactId > < version >${akka.version}</ version > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http_2.12</ artifactId > < version >${akka.http.version}</ version > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http-spray-json_2.12</ artifactId > < version >${akka.http.version}</ version > </ dependency > </ dependencies > </ dependencyManagement > </ project >我使用的是依賴性管理模塊。
現在,子項目無需指定版本即可包含這些庫。 派生和管理版本至關重要。 如果版本不兼容,可能會帶來許多不愉快的驚喜。
現在,在子模塊上,由于版本是子模塊,因此聲明了沒有版本的版本。
<? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = " http://maven.apache.org/POM/4.0.0 " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation = " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd " > < parent > < artifactId >maven-dependency-management</ artifactId > < groupId >org.example</ groupId > < version >1.0-SNAPSHOT</ version > </ parent > < modelVersion >4.0.0</ modelVersion > < artifactId >child-one</ artifactId > < dependencies > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-stream_2.12</ artifactId > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http_2.12</ artifactId > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http-spray-json_2.12</ artifactId > </ dependency > </ dependencies > </ project >另一個需要注意的是,有時我們想使用另一個項目的依賴項管理,而不必將該項目作為父項。 在這些情況下,當您已經具有父項目時,您需要包括來自父項目的依賴關系管理。
<? xml version = "1.0" encoding = "UTF-8" ?> < project xmlns = " http://maven.apache.org/POM/4.0.0 " xmlns:xsi = " http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation = " http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd " > < modelVersion >4.0.0</ modelVersion > < groupId >org.example</ groupId > < artifactId >independent-project</ artifactId > < version >1.0-SNAPSHOT</ version > < dependencyManagement > < dependencies > < dependency > < artifactId >maven-dependency-management</ artifactId > < groupId >org.example</ groupId > < version >1.0-SNAPSHOT</ version > < type >pom</ type > < scope >import</ scope > </ dependency > </ dependencies > </ dependencyManagement > < dependencies > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-stream_2.12</ artifactId > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http_2.12</ artifactId > </ dependency > < dependency > < groupId >com.typesafe.akka</ groupId > < artifactId >akka-http-spray-json_2.12</ artifactId > </ dependency > </ dependencies > </ project >如您所見
< dependencyManagement > < dependencies > < dependency > < artifactId >maven-dependency-management</ artifactId > < groupId >org.example</ groupId > < version >1.0-SNAPSHOT</ version > < type >pom</ type > < scope >import</ scope > </ dependency > </ dependencies > </ dependencyManagement >我們包括了另一個項目的依賴性管理,可以將其應用于繼承多個項目的依賴性。
翻譯自: https://www.javacodegeeks.com/2020/06/dependency-management-and-maven.html
總結
以上是生活随笔為你收集整理的依赖管理和Maven的全部內容,希望文章能夠幫你解決所遇到的問題。
                            
                        - 上一篇: apache.camel_Apache
 - 下一篇: 护组词 护字怎么组词