在父pom中,我已經宣告了這些模塊。
`
<module>module1</module>
<module>/span>module2</module>/span>
<module>module3</module>
`
在每個子專案的pom中,我都宣告了父專案
。`
<groupId>com.group</groupId> /
<artifactId>parent-module</artifactId>
<version>--</version>
`
在父pom中,由于專案相關的限制,我選擇了跳過父pom的部署
父pom:我選擇了跳過。
parent pom: `
<plugins>
<plugin>/span>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>/span>
<skip> true</skip>
</configuration>/span>
</plugin>/span>
</plugins>/span>
</build>
`
這意味著我在部署它時只有三套Jar和Pom。
- childJar1
- 子Pom1
- 子Jar2
- childPom2
- 子壇3
- childPom3 。
然而,當我使用上述任何一個jar時,我在使用程序中遇到了錯誤,因為每個pom都宣告了父模塊,而父模塊卻不存在(因為我選擇了跳過父模塊的部署)。
我是否有辦法讓每個子模塊不宣告或尋找父模塊?
uj5u.com熱心網友回復:
通常情況下,正如khmarbaise所說,你應該只部署父模塊,一切都很好。這是標準的方法。
https://www.mojohaus.org/flatten-maven-plugin/
uj5u.com熱心網友回復:
跳過構建不應該阻止他們成為父母。但我認為你可能混淆了 "父代 "和 "依賴"。通常所有的模塊都有一個 "主父",然后在模塊之間級聯依賴關系。 還要確保你所說的父類不是 "聚合器":如果它們的唯一目的是列出模塊,你根本不需要設定構建配置,但你也不會對它們產生依賴關系。
下面是一個例子,很難使用你的資料,因為它并不完整
一個聚合器(重要的是:packaing:pom可以防止它試圖構建):<?xml version="1.0" encoding="UTF-8"? >
<project xmlns="http://maven.apache.org/POM/4.0.0"/span>
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"/span>>
<packaging>/span>pom</packaging>/span>
<modelVersion>/span>4.0.0</modelVersion>/span>
<groupId>com.foo</groupId>
<artifactId>components</artifactId>
<version>0.0.1-SNAPSHOT</version>/span>
<modules>/span>
<module>comp1</module>
<module>comp2</module>
<module>comp3</module>
</modules>/span>
</project>
其中一個模塊宣告:
<?xml version="1.0" encoding="UTF-8"? >
<project xmlns="http://maven.apache.org/POM/4.0.0"/span>
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"/span>>
<parent>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>/span>2.5.3</version>
<relativePath/> <!--從版本庫中查找父本--> < >
</parent>
<modelVersion>/span>4.0.0</modelVersion>/span>
<groupId>com.foo</groupId>
<artifactId>comp1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>/span>
<dependency>>
<groupId>/span>com.foo</groupId>/span>
<artifactId>core</artifactId>
<version>0.0.1-SNAPSHOT</version>/span>
</dependency>/span>
</dependencies>
<build>/span>
<plugins>/span>
<plugin>/span>
<groupId>org.springframework.boot</groupId>/span>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>/span>2.5.3</version>
<configuration>/span>
<skip> true</skip>
</configuration>/span>
</plugin>/span>
</plugins>/span>
</build>/span>
</project>
另一個模塊使用該模塊,雖然構建被跳過
<project xmlns="http://maven.apache.org/POM/4.0.0"/span>
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"/span>>
<parent>
<groupId>/span>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>/span>2.5.3</version>
<relativePath/> <!--從版本庫中查找父本--> < >
</parent>
<modelVersion>/span>4.0.0</modelVersion>/span>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>/span>
<dependencies>/span>
<dependency>>
<groupId>/span>com.foo</groupId>/span>
<artifactId>comp1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>/span>
</dependencies>
<build>/span>
<plugins>/span>
<plugin>/span>
<groupId>org.springframework.boot</groupId>/span>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>/span>2.5.3</version>
<configuration>/span>
<skip>/span>false</skip>
</configuration>/span>
</plugin>/span>
</plugins>/span>
</build>
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/310133.html
標籤:
