简体   繁体   中英

maven idea plugin unable to resolve local dependency

I have created a Maven (Java) project with three Maven subprojects, module1-3. module2 depends on module1, and module3 depends on both module2 and module1.

In the original build, module1 and module2 are common modules shared between multiple projects, and module3 is the end program which incorporates the other two. All the modules are ultimately compiled into an uber-jar to be distributed to the end customer.

From the command line this builds and runs just fine, but after importing to IntelliJ it's not able to properly resolve the local dependencies. It appears that IntelliJ uses the idea:idea goal for its importing, and running idea:idea on my testcase gives the following output, where it clearly has problems resolving despite ultimately giving a build success.

After importing the project into IntelliJ, all of the cross module references show as unresolved symbols.

Complete source code for this testcase is at: https://github.com/hutch31/maven-intellij-plugin-dep

Is there a missing/extra step required to get IntelliJ to figure out these references across Maven subprojects?

I am using Maven 3.6.3, and IntelliJ 2021.1. IntelliJ's integrated Maven is also version 3.6.3.

Edit: I have tried changing the order of the modules in the parent, and adding parent tags to the child modules, which did not affect the operation. I have updated the repository to reflect the state of the original code, in which module3 has a parent tag but module1 and module2 do not (as they are common code).

On the command line, I build and run using 'mvn clean test'. I have also added a Maven 'compile' configuration, which builds correctly despite the reported errors.

$ 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] ------------------------------------------------------------------------

The maven idea plugin is long deprecated:

https://maven.apache.org/plugins/maven-idea-plugin/

Avoid using it.

I believe I have figured out what the issue was in the testcase, which is that the package specification for mod1/mod2/mod3 did not match the file path. Moving the files from src/main/java/org/ghutchis/module1.java to src/main/java/org/ghutchis/mod1/module1.java fixed IntelliJ's build issue for the test case (though, sadly, not the original problem).

The updated Java code has been pushed to Github for examination.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM