• spring-boot-maven-plugin多模块install问题解决办法


    一、问题描述:

      项目分多个模块,open-eureka注册中心、open-provider服务提供者、open-common公共部分,provider依赖common。父pom使用spring-boot-maver-plugin插件,项目直接运行Main主类没问题,但是install报common中的类找不到符号.

    二、查找问题:

      spring-boot-maven-plugin 打包跟普通的apache-maven-plugin打包不一致,前者打的jar 包是可以直接用java -jar  name.jar 来执行的,但是common模块只是作为一个其他模块的依赖来使用,并不需要有启动类,也不需要执行。

    三、解决办法:

     3.1、删除父pom中的spring-boot-maven-plugin插件依赖,父pom不需要<build>

    parent.pom

    <?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>com.starfast.open</groupId>
        <artifactId>starfast-open</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <modules>
            <module>open-eureka</module>
            <module>open-provider</module>
            <module>open-feign</module>
            <module>open-common</module>
        </modules>
        <packaging>pom</packaging>
    
        <name>starfast-open</name>
    
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.1.4.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
            <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
            <witown.open.version>1.0-SNAPSHOT</witown.open.version>
            <open.common.version>0.0.1-SNAPSHOT</open.common.version>
        </properties>
    
        <dependencies>
    
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-core</artifactId>
                <version>1.2.3</version>
            </dependency>
            <dependency>
                <groupId>ch.qos.logback</groupId>
                <artifactId>logback-classic</artifactId>
                <version>1.2.3</version>
            </dependency>
            <dependency>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok</artifactId>
                <version>1.16.18</version>
            </dependency>
        </dependencies>
    
    
        <dependencyManagement>
            <!--引入spring-cloud依赖-->
            <dependencies>
                <dependency>
                    <groupId>org.springframework.cloud</groupId>
                    <artifactId>spring-cloud-dependencies</artifactId>
                    <version>${spring-cloud.version}</version>
                    <type>pom</type>
                    <scope>import</scope>
                </dependency>
    
                <dependency>
                    <groupId>com.witown.app</groupId>
                    <artifactId>open-sdk</artifactId>
                    <version>${witown.open.version}</version>
                </dependency>
    
                <dependency>
                    <groupId>com.starfast.open</groupId>
                    <artifactId>open-common</artifactId>
                    <version>${open.common.version}</version>
                </dependency>
            </dependencies>
        </dependencyManagement>
    
    
    </project>

     3.2、只在需要独立运行的模块,如provider模块中加载spring-boot-maven-plugin插件依赖  

    provider.pom

    <?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>starfast-open</artifactId>
            <groupId>com.starfast.open</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>open-provider</artifactId>
        <name>open-provider</name>
    
        <dependencies>
            <!--common模块-->
            <dependency>
                <groupId>com.starfast.open</groupId>
                <artifactId>open-common</artifactId>
            </dependency>
        </dependencies>
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    
    </project>

    3.3、删除不需要独立运行的模块中的spring-boot-maven-plugin插件依赖

    common.pom

    <?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>starfast-open</artifactId>
            <groupId>com.starfast.open</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
        <modelVersion>4.0.0</modelVersion>
        <artifactId>open-common</artifactId>
        <packaging>jar</packaging>
        <name>open-common</name>
    
        <dependencies>
            <!--web-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <!--eureka client-->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
            </dependency>
            <!--redis-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-redis</artifactId>
            </dependency>
    
            <!--开放平台-->
            <dependency>
                <groupId>com.witown.app</groupId>
                <artifactId>open-sdk</artifactId>
            </dependency>
            <!--监控-->
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-actuator</artifactId>
            </dependency>
            <!--单元测试-->
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
        </dependencies>
    
    </project>

    install结果:

    顺便吐槽,网上的垃圾文章真多,还好发现了该篇文章,

    https://blog.csdn.net/SnailMann/article/details/81710461

    多谢作者。

  • 相关阅读:
    64win7+64Oracle+32plsql
    Delphi与Java中的日期互换
    QT变异版本下载(SJLJ长跳转,DWARF不传递错误(32位专用),SEH(64位专用)),以及QT的实验室项目
    顿悟,职业生涯最重要的是行业水平的积累,而不是多学某一门语言(很危险)——遥想铁血强人刘志军对铁路行业的理解以及执行力
    天下古今之庸人,皆以一惰字致败(联想到了自己的高考数学大题)
    这七种情况下,不要创业
    Android 点击桌面快捷方式和Notifycation跳转到Task栈顶Activity
    字符串模式匹配算法——BM、Horspool、Sunday、KMP、KR、AC算法一网打尽
    QSplashScreen开机画面(不断的repaint)
    一个QT 3D转动控件
  • 原文地址:https://www.cnblogs.com/geekdc/p/10744903.html
Copyright © 2020-2023  润新知