maven 依赖 不生效

1.问题描述:

Maven 依赖必须申明在父工程pom中,若写在子工程pom,则依赖不生效>_<,求各位好大Lao解惑!需将依赖申明在子工程中并生效明

2.申明在父工程中,可正常加载依赖

2.1父工程pom截图

img

2.2子工程pom截图

img

2.3使用注解代码

img

3.申明在子工程中,不能正常加载依赖

3.1父工程pom截图

img

3.2子工程pom截图

img

3.3使用注解代码

img

4.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>pom</packaging>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.10</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.smart.classroom</groupId>
    <artifactId>smart-classroom-subscription</artifactId>
    <version>1.0.0</version>
    <name>smart-classroom-subscription</name>
    <description>smart-classroom-subscription</description>
    <properties>
        <java.version>1.8</java.version>
    </properties>

    <modules>
        <module>scs-utility</module>
    </modules>

</project>
<?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">
    <parent>
        <artifactId>smart-classroom-subscription</artifactId>
        <groupId>com.smart.classroom</groupId>
        <version>1.0.0</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>scs-utility</artifactId>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <!-- *********************工具库 start********************* -->

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

        <!-- *********************工具库 end********************* -->
    </dependencies>

</project>
import lombok.Getter;

public enum SortDirection {
    ASC("升序"),
    DESC("降序");;

    @Getter
    private final String description;

    SortDirection(String description) {
        this.description = description;
    }


    public static String toString(SortDirection orderStatus) {
        if (orderStatus == null) {
            return null;
        }
        return orderStatus.name();
    }

    public static SortDirection toEnum(String s) {
        if (s == null) {
            return null;
        }
        return SortDirection.valueOf(s);
    }
}

img


maven是否有子项目pom,没有的话,上边点加号添加该子项目pom试试

去学一下maven就知道了
http://t.csdn.cn/rMy3v
依赖的传递性

参考 https://blog.csdn.net/fxkcsdn/article/details/97620503

  • 这个问题的回答你可以参考下: https://ask.csdn.net/questions/7724146
  • 我还给你找了一篇非常好的博客,你可以看看是否有帮助,链接:Maven中已向pom文件引入依赖,仍旧提示无法解析为类型
  • 除此之外, 这篇博客: 学习笔记之maven中pom爆红问题解决中的 解决 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 加入版本号如下,之后即使删除版本号也不汇报红,不知道版本号,一般输入 在这输入2或3会自动出现最新版本号,可以随意选择,如果不显示可以百度版本号,如果maven加了版本号刷新继续爆红,可能是idea没有及时更新,可以重启idea

      <!-- Srping Boot 打包工具 -->
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                     <version>2.3.9.RELEASE</version>
                    <configuration>
                        <fork>true</fork>
                    </configuration>
                </plugin>
                <!-- 指定JDK编译版本 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.1</version> 
                </plugin>