开发者社区> 问答> 正文

idea maven 多module工程怎么关联源码而不是关联本地仓库的jar?报错

如图所示,新建了一个简单的工程,结构为:

wrap

-main 依赖mod工程

-mod

配置没问题,但在main工程里配置了jetty插件运行就会 报错,找不到mod这个依赖的jar

[ERROR] Failed to execute goal on project main: Could not resolve dependencies for project com.kongwu:main:war:1.0: Failure to find com.kongwu:mod🏺1.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]


,怎么 让他依赖于module里的文件呢,而不是依赖本地jar?

展开
收起
爱吃鱼的程序员 2020-06-09 10:15:38 1611 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    其实没父目录的maven工程是有问题的。这边公司是这样的。

    正确的做法是

    root

    |-web

    |-service

    |-dao

    这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

    你可以新建project,选maven,然后一路下去。

    建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

    最后一个编译就OK了

    [INFO]Scanningforprojects...
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorBuildOrder:
    [INFO] 
    [INFO]TestMaven
    [INFO]dao
    [INFO]service
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]BuildingTestMaven1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@TestMaven---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@TestMaven---
    [INFO]InstallingD:\workspace\testMaven\pom.xmltoD:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingdao1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@dao---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO]Buildingjar:D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@dao---
    [INFO]InstallingD:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\dao\pom.xmltoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingservice1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@service---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO]Buildingjar:D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@service---
    [INFO]InstallingD:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\service\pom.xmltoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorSummary:
    [INFO] 
    [INFO]TestMaven..........................................SUCCESS[ 0.709s]
    [INFO]dao................................................SUCCESS[ 0.949s]
    [INFO]service............................................SUCCESS[ 0.088s]
    [INFO]------------------------------------------------------------------------
    [INFO]BUILDSUCCESS
    [INFO]------------------------------------------------------------------------
    [INFO]Totaltime:1.848s
    [INFO]Finishedat:2016-09-27T17:35:34+08:00
    [INFO]FinalMemory:11M/150M
    [INFO]------------------------------------------------------------------------


    Processfinishedwithexitcode0


    是我哪里弄错了么,还是idea就这么设计的嗯。我也是这么做的,但是jetty:run之后他就报错找不到依赖module的jar。。应该会找依赖项目的文件才对吧?pom.xml里面配置啊···依赖这个子模块我已经配置好了,但运行的时候他还是去本地仓库找mod这个jar,而不找模块的源码


    添加项目依赖。(这个只是保证编译时不报错)

    另外还要在子POMMOD中,加入一句这个

      
       <
       
        parent
        
         >
         
          <
          
           groupId
           
            >父GROUPID
            
             </
             
              groupId
              
               >
               
                <
                
                 artifactId
                 
                  >父ARTIFACTID
                  
                   </
                   
                    artifactId
                    
                     >
                     
                      <
                      
                       version
                       
                        >父版本
                        
                         </
                         
                          version
                          
                           >
                           
                            <
                            
                             relativePath
                             
                              >../mod/pom.xml
                              
                               </
                               
                                relativePath
                                
                                 >
                                 
                                  </
                                  
                                   parent
                                   
                                    >
                                   
                                  
                                 
                                
                               
                              
                             
                            
                           
                          
                         
                        
                       
                      
                     
                    
                   
                  
                 
                
               
              
             
            
           
          
         
        
       
      
    把mod移动和wap同级,然后修改mod中的pom代码如上。

    工程如下这样:


    怎么做到没有父目录,把这个移动到上层目录的。。。还有这一步有什么用呢

    引用来自“szwx855”的评论

    其实没父目录的maven工程是有问题的。这边公司是这样的。

    正确的做法是

    root

    |-web

    |-service

    |-dao

    这些模块中都有pom。然后root中配置好pom后。在各个子系统中加点依赖就行了。

    你可以新建project,选maven,然后一路下去。

    建设好的工程中,在添加module,选择父节点为root,然后添加好子工程。

    最后一个编译就OK了

    [INFO]Scanningforprojects...
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorBuildOrder:
    [INFO] 
    [INFO]TestMaven
    [INFO]dao
    [INFO]service
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]BuildingTestMaven1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@TestMaven---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@TestMaven---
    [INFO]InstallingD:\workspace\testMaven\pom.xmltoD:\mvn_repo\TestMaven\TestMaven\1.0-SNAPSHOT\TestMaven-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingdao1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@dao---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO]Buildingjar:D:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@dao---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\dao\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@dao---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@dao---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@dao---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@dao---
    [INFO]InstallingD:\workspace\testMaven\dao\target\dao-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\dao\pom.xmltoD:\mvn_repo\TestMaven\dao\1.0-SNAPSHOT\dao-1.0-SNAPSHOT.pom
    [INFO]                                     
    [INFO]------------------------------------------------------------------------
    [INFO]Buildingservice1.0-SNAPSHOT
    [INFO]------------------------------------------------------------------------
    [INFO] 
    [INFO]---maven-clean-plugin:2.5:clean(default-clean)@service---
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO]Buildingjar:D:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jar
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:resources(default-resources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]Copying0resource
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:compile(default-compile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-resources-plugin:2.6:testResources(default-testResources)@service---
    [WARNING]Usingplatformencoding(UTF-8actually)tocopyfilteredresources,i.e.buildisplatformdependent!
    [INFO]skipnonexistingresourceDirectoryD:\workspace\testMaven\service\src\test\resources
    [INFO] 
    [INFO]---maven-compiler-plugin:3.1:testCompile(default-testCompile)@service---
    [INFO]Nothingtocompile-allclassesareuptodate
    [INFO] 
    [INFO]---maven-surefire-plugin:2.12.4:test(default-test)@service---
    [INFO]Noteststorun.
    [INFO]Skippingexecutionofsurefirebecauseithasalreadybeenrunforthisconfiguration
    [INFO] 
    [INFO]---maven-jar-plugin:2.4:jar(default-jar)@service---
    [INFO] 
    [INFO]---maven-install-plugin:2.4:install(default-install)@service---
    [INFO]InstallingD:\workspace\testMaven\service\target\service-1.0-SNAPSHOT.jartoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.jar
    [INFO]InstallingD:\workspace\testMaven\service\pom.xmltoD:\mvn_repo\TestMaven\service\1.0-SNAPSHOT\service-1.0-SNAPSHOT.pom
    [INFO]------------------------------------------------------------------------
    [INFO]ReactorSummary:
    [INFO] 
    [INFO]TestMaven..........................................SUCCESS[ 0.709s]
    [INFO]dao................................................SUCCESS[ 0.949s]
    [INFO]service............................................SUCCESS[ 0.088s]
    [INFO]------------------------------------------------------------------------
    [INFO]BUILDSUCCESS
    [INFO]------------------------------------------------------------------------
    [INFO]Totaltime:1.848s
    [INFO]Finishedat:2016-09-27T17:35:34+08:00
    [INFO]FinalMemory:11M/150M
    [INFO]------------------------------------------------------------------------


    Processfinishedwithexitcode0


    回复 @空无:jetty是必须打包的。这个木有办法。所以我都用resin或者tomcat.这个jetty,在本地开必debug很蛋疼。回复 @szwx855:我换了几个环境换了电脑都是同样的结果,经测试,直接配置个本地tomcat是可以正常依赖module的,junit/main方法运行也是可以依赖的,但mavenjetty/tomcat插件跑的话就必须先把module打包到本地仓库,还是很感谢你!回复 @空无:一般是加载本地仓库的jar,在idea中看代码跟踪到jar的时候,因为它会自动反编译,所以这个时候,你点下这个class右上上角的downloadsource,然后在选择chooseSource,就定位到源码了。都有的,你的可以正常加载代码而不是本地仓库的jar吗?你看本地仓库有没有对应的jar,你删掉在看看
    2020-06-09 10:15:55
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
蚂蚁金服高级开发工程师萧恺:IDEA 插件开发入门教程 立即下载
Project Fortis 立即下载
低代码开发师(初级)实战教程 立即下载

相关镜像