Maven父子結構的項目依賴使用以及打包依賴


1:在父子結構項目中,如果要是用其他模塊的類。在當前項目中的pom中 加入 其他模塊的配置

   <dependency>
      <groupId>com.spring.mySpring</groupId>
      <artifactId>mySpring-utils</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>

其中的groupId與artifactId還有version要與對應的模塊一致

2:如果當前模塊依賴其他模塊,而且在打包的時候需要把依賴也打進去,則需要配置

<build>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <!-- 指定程序的主類 -->
             <configuration>
                    <mainClass>org.mySpring.service.TestService</mainClass>
             </configuration>
             <executions>
                 <execution>
                     <goals>
                         <goal>repackage</goal>
                     </goals>
                 </execution>
             </executions>
         </plugin>
     </plugins>
 
 </build>

3:總的pom示例如下

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  
  <parent>
    <groupId>com.spring.mySpring</groupId>
    <artifactId>mySpring-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  
  <artifactId>mySpring-service</artifactId>
  <name>mySpring-service</name>
  <url>http://maven.apache.org</url>
  
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    
    <!--  使用其他子模塊的依賴  -->
    <dependency>
      <groupId>com.spring.mySpring</groupId>
      <artifactId>mySpring-utils</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
  
  <!-- 打包的時候帶其他的子模塊 -->
 <build>
     <plugins>
         <plugin>
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-maven-plugin</artifactId>
             <!-- 指定程序的主類 -->
             <configuration>
                    <mainClass>org.mySpring.service.TestService</mainClass>
             </configuration>
             <executions>
                 <execution>
                     <goals>
                         <goal>repackage</goal>
                     </goals>
                 </execution>
             </executions>
         </plugin>
     </plugins>
 
 </build>
</project>

 


免責聲明!

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



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