当前位置:  开发笔记 > 编程语言 > 正文

找不到Maven多模块依赖包

如何解决《找不到Maven多模块依赖包》经验,为你挑选了1个好方法。

我有一个多模块项目:父POM.xml:



    4.0.0

    
        org.springframework.boot
        spring-boot-starter-parent
        1.4.3.RELEASE
    

    be.bodyreset
    bodyreset-parent
    1.0.0-SNAPSHOT
    pom

    Bodyreset Parent
    Manages the common properties and dependencies for the child modules

    
        bodyreset-commons
        messaging-contract
        discovery-microservice
        api-gateway-microservice
        rest-client-microservice
        email-commons
        security-microservice
        user-microservice
        point-of-service-microservice
    

    
        bodyreset
        1.8
        1.6.6
    

    
        
            ...
        
    

    
        
            
                
                    com.spotify
                    docker-maven-plugin
                    0.4.11
                
                
                    org.apache.maven.plugins
                    maven-compiler-plugin
                    3.6.0
                    
                        ${java.version}
                        ${java.version}
                    
                
                
                    org.apache.maven.plugins
                    maven-jar-plugin
                    3.0.2
                
            
        
    

rest-client-microservice的POM.xml如下所示:



    4.0.0

    
        be.bodyreset
        bodyreset-parent
        1.0.0-SNAPSHOT
    

    rest-client-microservice
    1.0.0-SNAPSHOT
    jar

    Rest Client Microservice
    Manages the REST clients to use for inter-service communication

    
        
            org.apache.commons
            commons-lang3
        
        
            org.projectlombok
            lombok
        
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-hateoas
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
            org.springframework.cloud
            spring-cloud-starter-eureka
        
        
            org.springframework.cloud
            spring-cloud-starter-feign
        
        
            org.springframework.cloud
            spring-cloud-starter-hystrix
        
    

    
        
            
                com.spotify
                docker-maven-plugin
                
                    
                        package
                        
                            build
                        
                    
                
                
                    ${docker.image.prefix}/${project.artifactId}
                    ${project.basedir}/src/main/docker
                    
                        
                            /
                            ${project.build.directory}
                            ${project.build.finalName}.jar
                        
                    
                
            
            
                org.apache.maven.plugins
                maven-jar-plugin
                
                    
                        
                            test-jar
                        
                    
                
            
            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    
                        
                            repackage
                        
                    
                
            
        
    

email-commons模块的POM.xml如下所示:



    4.0.0

    
        be.bodyreset
        bodyreset-parent
        1.0.0-SNAPSHOT
    

    email-commons
    1.0.0-SNAPSHOT
    jar

    Email Commons
    Enables sending emails via SMPT

    
        
            be.bodyreset
            rest-client-microservice
            1.0.0-SNAPSHOT
        
        
            be.bodyreset
            rest-client-microservice
            1.0.0-SNAPSHOT
            test-jar
            test
        
        
            org.apache.commons
            commons-lang3
        
        
            org.projectlombok
            lombok
        
        
            org.powermock
            powermock-api-mockito
            test
        
        
            org.powermock
            powermock-module-junit4
            test
        
        
            org.springframework.boot
            spring-boot-starter-mail
        
        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
    

    
        
            
                org.apache.maven.plugins
                maven-jar-plugin
                
                    
                        
                            test-jar
                        
                    
                
            
        
    

如果我尝试maven clean install在父项目上执行a ,我会得到以下结果:

[INFO] ------------------------------------------------------------------------
[INFO] Building Email Commons 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.6.1:clean (default-clean) @ email-commons ---
[INFO] Deleting /home/developer/ideaProjects/bodyreset/email-commons/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ email-commons ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO] Copying 2 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.6.0:compile (default-compile) @ email-commons ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 17 source files to /home/developer/ideaProjects/bodyreset/email-commons/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToRecipientConverter.java:[4,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToRecipientConverter.java:[16,63] cannot find symbol
  symbol: class UserDTO
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToRecipientConverter.java:[22,30] cannot find symbol
  symbol:   class UserDTO
  location: class be.bodyreset.mail.converter.UserDTOToRecipientConverter
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToSenderConverter.java:[4,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToSenderConverter.java:[5,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToSenderConverter.java:[15,60] cannot find symbol
  symbol: class UserDTO
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/converter/UserDTOToSenderConverter.java:[21,27] cannot find symbol
  symbol:   class UserDTO
  location: class be.bodyreset.mail.converter.UserDTOToSenderConverter
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[7,32] package be.bodyreset.rest.client does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[8,32] package be.bodyreset.rest.client does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[9,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[10,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[34,13] cannot find symbol
  symbol:   class PointOfServiceClient
  location: class be.bodyreset.mail.service.impl.SenderServiceImpl
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[37,13] cannot find symbol
  symbol:   class UserClient
  location: class be.bodyreset.mail.service.impl.SenderServiceImpl
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/SenderServiceImpl.java:[63,13] cannot find symbol
  symbol:   class PointOfServiceDTO
  location: class be.bodyreset.mail.service.impl.SenderServiceImpl
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/RecipientServiceImpl.java:[7,32] package be.bodyreset.rest.client does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/RecipientServiceImpl.java:[8,29] package be.bodyreset.rest.dto does not exist
[ERROR] /home/developer/ideaProjects/bodyreset/email-commons/src/main/java/be/bodyreset/mail/service/impl/RecipientServiceImpl.java:[32,13] cannot find symbol
  symbol:   class UserClient
  location: class be.bodyreset.mail.service.impl.RecipientServiceImpl
[INFO] 17 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Bodyreset Parent .................................. SUCCESS [0.690s]
[INFO] Bodyreset Commons ................................. SUCCESS [7.444s]
[INFO] Messaging Contract ................................ SUCCESS [1.751s]
[INFO] Discovery Microservice ............................ SUCCESS [19.925s]
[INFO] API Gateway Microservice .......................... SUCCESS [17.272s]
[INFO] Rest Client Microservice .......................... SUCCESS [15.271s]
[INFO] Email Commons ..................................... FAILURE [1.026s]
[INFO] Security Microservice ............................. SKIPPED
[INFO] User Microservice ................................. SKIPPED
[INFO] Point Of Service Microservice ..................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:04.292s
[INFO] Finished at: Thu Jan 19 11:53:25 CET 2017
[INFO] Final Memory: 63M/656M
[INFO] ------------------------------------------------------------------------

我已经在这个问题上突破了好几天了,但是我不知道为什么这不起作用.



1> Christiaan J..:

我想到了.rest-client-microservice是一个Spring Boot项目,使用以下插件:


    org.springframework.boot
    spring-boot-maven-plugin
    
        
            
                repackage
            
        
    

jar被重新打包,所有的包和类都放在BOOT-INF文件夹中.这就是为什么Maven无法找到它们的原因.您可以通过定义插件来解决此问题:


    org.springframework.boot
    spring-boot-maven-plugin
    
        
            
                repackage
            
            
                exec
            
        
    

使用此配置,Spring Boot Maven插件将创建2个JAR:主要的一个将与通常的Maven项目相同,而第二个将附加分类器并且是可执行的JAR.

推荐阅读
手机用户2402851335
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有