mvn install 抛出错误“Pacakage ...不存在”,即使它存在

问题描述

在使用 client-a 中使用的 controller 中的类实例构建 java 项目时,我遇到编译错误

/path/to/file/project/controller/Config.java [50,1] package com.stuff.clienta does not exist
cannot find symbol ClientAClass

所以我最近使用 Maven 在多模块 java 项目中添加了两个新模块。 module-aclient-a。这样 module-a 依赖于 client-a。这个项目也有现有的模块,有一个“主”模块初始化项目中的所有bean,称为controller,因此,controller依赖于client-a

运行 mvn install 时,我仅在引用 client-a 中的 controller 中的文件时收到错误module-b 构建良好。

我已经浏览了此处 (Maven,package does not exist) 的所有答案,但无法解决此问题。

另外,在 controller pom 中,我添加了这样的依赖

        <dependency>
            <groupId>com.stuff.clienta</groupId>
            <artifactId>client-a</artifactId>
        </dependency>

module-a 中的方式完全相同,我确认 maven reactor 正在工作,因为有了这个依赖项,client-a 首先构建,没有,client-a 在最后构建。

另外,父 pom 在 dependencyManagement 部分有 client-a 作为依赖:

            <dependency>
                <groupId>com.stuff.clienta</groupId>
                <artifactId>client-a</artifactId>
                <version>${project.version}</version>
            </dependency>

任何指导都会有所帮助。在这一点上,我真的不认为它与 pom 相关,而是构建中的某些东西。我试过删除 target 文件夹和 .m2 文件夹(仅针对此项目)然后重建,但我遇到了同样的问题...

编辑: 父pom信息

<?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>
    <packaging>pom</packaging>
    <modules>
        <module>controller</module>
        <module>module-a</module>
        <module>client-a</module>
    </modules>

    <groupId>com.stuff</groupId>
    <artifactId>root</artifactId>
    <version>1.0</version>
    <name>root</name>
    <description>Stuff</description>

    <properties>
        ... versions
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring.boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>controller</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>module-a</artifactId>
                <version>${project.version}</version>
            </dependency>
            <dependency>
                <groupId>com.stuff</groupId>
                <artifactId>client-a</artifactId>
                <version>${project.version}</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                ... springboot,mojo,checkstyle
            </plugins>
        </pluginManagement>
        <plugins>
            ... jacoco,checkstyle,maven
        </plugins>
        <extensions>
            ...
        </extensions>
    </build>
</project>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)