无法解决Maven多模块项目中的依赖关系

时间:2019-07-08 11:40:20

标签: java maven spring-boot pom.xml parent-pom

即使有其他问题,我仍在发布此问题。但是,到目前为止,我还没有找到任何解决方案,因此发布了这个问题。

我遇到此错误:

Could not resolve dependencies for project vehicle-tracker:vehicle-simulator:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Failed to read artifact descriptor for vehicle-tracker:common-libs:jar:0.0.1-SNAPSHOT: Could not find artifact vehicle-tracker:vehicle-tracker:pom:0.0.1-SNAPSHOT

公共库jar位于

.m2\repository\vehicle-tracker\common-libs\0.0.1-SNAPSHOT

我要构建的项目依赖于common-libs jar,但是在本地Maven存储库中找不到Maven。

我要附加以下POM.xml

Parent.xml

    <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>vehicle-tracker</groupId>
  <artifactId>vehicle-tracker</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

  <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

  <dependencies>
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        </dependencies>
  <modules>
    <module>common-libs</module>
    <module>vehicle-simulator</module>
    <module>tracker-dashboard</module>
  </modules>

</project>

公共库POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>vehicle-tracker</groupId>
        <artifactId>vehicle-tracker</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../../vehicle-tracker</relativePath> <!-- lookup parent from repository -->
    </parent>
    <artifactId>common-libs</artifactId>
    <name>common-libs</name>
    <description>Common libraries for vehicle tracker</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

车辆模拟器POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>vehicle-tracker</groupId>
        <artifactId>vehicle-tracker</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../../vehicle-tracker/</relativePath> <!-- lookup parent from repository -->
    </parent>
    <artifactId>vehicle-simulator</artifactId>
    <name>vehicle-simulator</name>
    <description>vehicle simulator for application</description>

    <properties>
        <java.version>1.8</java.version>
        <swagger-version>2.9.2</swagger-version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.kafka</groupId>
            <artifactId>spring-kafka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>${swagger-version}</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>${swagger-version}</version>
        </dependency>

        <dependency>
            <artifactId>common-libs</artifactId>
            <version>0.0.1-SNAPSHOT</version><!--${project.version}-->
            <groupId>vehicle-tracker</groupId><!-- ${project.groupId} -->
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

我无法找到我在POM中做错的地方或其他地方...因此无法构建项目车辆跟踪器。

1 个答案:

答案 0 :(得分:0)

我解决了构建错误。实际上,我将下面的内容放在common-libs模块的POM.xml中:

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

这应该在创建spring-boot jar时位于commons-lib模块的POM.xml中。因此,依赖项不可用于依赖模块。 从commons-lib模块中删除POM.xml中的此配置块后,我可以构建项目而没有任何问题。

感谢您所有人对此的关注。 如果有任何一个人有意或无意面对这个问题,就分享一下。