Maven建立父级pom文件需关注的地方

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013233360/article/details/89952101

建立SpringBoot父级pom文件

我们在开发springboot项目时,一般会建立父pom文件,maven子模块可以引用父pom文件,这样就会使项目pom结构分明,层次清晰。

在pom文件中添加项目中依赖的文件后,需要打包上传至maven私服库中,这时需要使用 mvn deploy 命令进行打包上传。

maven会根据setting.xml找到maven项目私服库地址,上传至私服库后,进行子模块开发时,就可以进行引用了。

此处,用的是Nexus私服maven库,配置好nexus后,在父pom文件中需要引用上传nexus的地址。如下:

<distributionManagement>
    <repository>
        <id>releases</id>
        <!-- 这个ID需要与你的release仓库的Repository ID一致  -->
        <url>
            http://x.x.x.x:18888/nexus/content/repositories/releases
        </url>
    </repository>
    <snapshotRepository>
        <id>snapshots</id>
        <!-- 这个ID需要与你的snapshots仓库的Repository ID一致  -->
        <url>
            http://x.x.x.x:18888/nexus/content/repositories/snapshots
        </url>
    </snapshotRepository>
</distributionManagement>

如果该parent只是为了打pom类型的jar包时,需要去除掉springboot自带的maven插件,否则打包时会出现如下错误: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin 导致错误的原因是因为pom引用了如下配置:

 <build>
    <plugins>
	  <plugin>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-maven-plugin</artifactId>
          </plugin>
    </plugins>
 </build>

这里引入spring-boot-maven-plugin,打包时会扫描main方法入口,也就是说引入该配置后,就需要在项目src/main/java目录下创建一个springboot启动类,如下:

 @SpringBootApplication
 public class DemoApplication {

     public static void main(String[] args) {
          SpringApplication.run(DemoApplication.class, args);
    }

  }

注意:入口类上一定要加上注解@SpringBootApplication

此处是为了创建父级的pom依赖jar,故需要去除掉spring-boot-maven-plugin插件。

引用完依赖jar后,就可以使用

mvn deploy 命令进行打包部署至nexus私服中。

猜你喜欢

转载自blog.csdn.net/u013233360/article/details/89952101
今日推荐