Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

java - Maven cannot resolve dependency for module in same multi-module project

When running commands such as

mvn dependency:build-classpath

or

mvn exec:java

Maven is unable to resolve a dependency of one of my modules on another.

[ERROR] Failed to execute goal on project parser-app: Could not resolve dependencies for project project_group:A:jar:0.1-SNAPSHOT: Could not find artifact project_group:B:jar:0.1-SNAPSHOT

The project structure is as follows:

/pom.xml
/A/pom.xml
/B/pom.xml

The parent pom is as follows:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>project_group</groupId>
  <artifactId>parent</artifactId>
  <packaging>pom</packaging>
  <version>0.1-SNAPSHOT</version>
  <name>parent</name>

  <modules>
    <module>A</module>
    <module>B</module>
  </modules>

The first child module (the one failing to resolve the dependency):

    <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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>parent_group</groupId>
    <artifactId>parent</artifactId>
    <version>0.1-SNAPSHOT</version>
  </parent>
  <artifactId>A</artifactId>
  <packaging>jar</packaging>
  <name>A</name>

  <dependencies>
    <dependency>
      <groupId>parent_group</groupId>
      <artifactId>B</artifactId>
      <version>0.1-SNAPSHOT</version>
    </dependency>

The second child module (the dependency):

  <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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>parent_group</groupId>
    <artifactId>parent</artifactId>
    <version>0.1-SNAPSHOT</version>
  </parent>
  <artifactId>B</artifactId>
  <packaging>jar</packaging>
  <name>B</name>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Have you run mvn clean install at least once on the project to install the dependencies within your local repository?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...