maven idea插件无法解析本地依赖关系

4dbbbstv  于 2021-07-14  发布在  Java
关注(0)|答案(2)|浏览(406)

我创建了一个maven(java)项目,其中包含三个maven子项目module1-3。module2依赖于module1,module3同时依赖于module2和module1。
在最初的构建中,module1和module2是多个项目之间共享的公共模块,module3是合并其他两个项目的最终程序。所有模块最终都被编译成一个uberjar,分发给最终客户。
从命令行生成并运行得很好,但是在导入intellij之后,它无法正确解析本地依赖关系。看起来intellij使用idea:idea goal 用于导入和运行idea:idea on 我的testcase给出了以下输出,尽管最终获得了构建成功,但它显然在解决这些问题时遇到了问题。
将项目导入intellij后,所有跨模块引用都显示为未解析的符号。
此测试用例的完整源代码位于:https://github.com/hutch31/maven-intellij-plugin-dep
要让intellij在maven子项目中找出这些引用,是否需要缺少/额外的步骤?
我使用的是maven 3.6.3和intellij 2021.1。intellij的集成maven也是3.6.3版。
编辑:我尝试更改父模块中模块的顺序,并将父标记添加到子模块中,这不会影响操作。我已经更新了存储库以反映原始代码的状态,其中module3有一个父标记,而module1和module2没有(因为它们是公共代码)。
在命令行上,我使用“mvn clean test”构建和运行。我还添加了一个maven“compile”配置,尽管报告了错误,但它仍能正确构建。

$ mvn idea:idea
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] mod1                                                               [jar]
[INFO] mod2                                                               [jar]
[INFO] mod3                                                               [jar]
[INFO] Cable Test Studio                                                  [pom]
[INFO]
[INFO] -------------------------< org.ghutchis:mod1 >--------------------------
[INFO] Building mod1 1.0-SNAPSHOT                                         [1/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> maven-idea-plugin:2.2.1:idea (default-cli) > generate-resources @ mod1 >>>
[INFO]
[INFO] <<< maven-idea-plugin:2.2.1:idea (default-cli) < generate-resources @ mod1 <<<
[INFO]
[INFO]
[INFO] --- maven-idea-plugin:2.2.1:idea (default-cli) @ mod1 ---
[INFO]
[INFO] -------------------------< org.ghutchis:mod2 >--------------------------
[INFO] Building mod2 1.0-SNAPSHOT                                         [2/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> maven-idea-plugin:2.2.1:idea (default-cli) > generate-resources @ mod2 >>>
[INFO]
[INFO] <<< maven-idea-plugin:2.2.1:idea (default-cli) < generate-resources @ mod2 <<<
[INFO]
[INFO]
[INFO] --- maven-idea-plugin:2.2.1:idea (default-cli) @ mod2 ---
[WARNING] An error occurred during dependency resolution of the following artifact:

    org.ghutchis:mod21.0-SNAPSHOT

Caused by: Missing:
----------
1) org.ghutchis:mod1:jar:1.0-SNAPSHOT

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.ghutchis -DartifactId=mod1 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.ghutchis -DartifactId=mod1 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) org.ghutchis:mod2:jar:1.0-SNAPSHOT
        2) org.ghutchis:mod1:jar:1.0-SNAPSHOT

----------
1 required artifact is missing.

for artifact:
  org.ghutchis:mod2:jar:1.0-SNAPSHOT

from the specified remote repositories:
  central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)

[INFO]
[INFO] -------------------------< org.ghutchis:mod3 >--------------------------
[INFO] Building mod3 1.0-SNAPSHOT                                         [3/4]
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] >>> maven-idea-plugin:2.2.1:idea (default-cli) > generate-resources @ mod3 >>>
[INFO]
[INFO] <<< maven-idea-plugin:2.2.1:idea (default-cli) < generate-resources @ mod3 <<<
[INFO]
[INFO]
[INFO] --- maven-idea-plugin:2.2.1:idea (default-cli) @ mod3 ---
[WARNING] An error occurred during dependency resolution of the following artifact:

    org.ghutchis:mod31.0-SNAPSHOT

Caused by: Missing:
----------
1) org.ghutchis:mod2:jar:1.0-SNAPSHOT

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.ghutchis -DartifactId=mod2 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.ghutchis -DartifactId=mod2 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) org.ghutchis:mod3:jar:1.0-SNAPSHOT
        2) org.ghutchis:mod2:jar:1.0-SNAPSHOT

2) org.ghutchis:mod1:jar:1.0-SNAPSHOT

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.ghutchis -DartifactId=mod1 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:
      mvn deploy:deploy-file -DgroupId=org.ghutchis -DartifactId=mod1 -Dversion=1.0-SNAPSHOT -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency:
        1) org.ghutchis:mod3:jar:1.0-SNAPSHOT
        2) org.ghutchis:mod1:jar:1.0-SNAPSHOT

----------
2 required artifacts are missing.

for artifact:
  org.ghutchis:mod3:jar:1.0-SNAPSHOT

from the specified remote repositories:
  central (https://repo.maven.apache.org/maven2, releases=true, snapshots=false)

[INFO]
[INFO] ------------------------< org.ghutchis:parent >-------------------------
[INFO] Building Cable Test Studio 1.0-SNAPSHOT                            [4/4]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO]
[INFO] >>> maven-idea-plugin:2.2.1:idea (default-cli) > generate-resources @ parent >>>
[INFO]
[INFO] <<< maven-idea-plugin:2.2.1:idea (default-cli) < generate-resources @ parent <<<
[INFO]
[INFO]
[INFO] --- maven-idea-plugin:2.2.1:idea (default-cli) @ parent ---
[INFO] jdkName is not set, using [java version1.8.0_265] as default.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary for Cable Test Studio 1.0-SNAPSHOT:
[INFO]
[INFO] mod1 ............................................... SUCCESS [  0.231 s]
[INFO] mod2 ............................................... SUCCESS [  0.021 s]
[INFO] mod3 ............................................... SUCCESS [  0.021 s]
[INFO] Cable Test Studio .................................. SUCCESS [  0.087 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.750 s
[INFO] Finished at: 2021-04-20T10:28:53+01:00
[INFO] ------------------------------------------------------------------------
arknldoa

arknldoa1#

maven idea插件长期以来一直不受欢迎:
https://maven.apache.org/plugins/maven-idea-plugin/
避免使用它。

c9qzyr3d

c9qzyr3d2#

我相信我已经找出了testcase中的问题所在,即mod1/mod2/mod3的包规范与文件路径不匹配。将文件从src/main/java/org/ghutchis/module1.java移到src/main/java/org/ghutchis/mod1/module1.java修复了intellij在测试用例中的构建问题(不过,遗憾的是,这并不是最初的问题)。
更新后的java代码已被推送到github进行检查。

相关问题