执行mvn build失败,错误显示: “SLF4J: Class path contains multiple SLF4J bindings”以及“无效的目标发行版:15.0“,让我来来看看~

SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/eclipse-jee-2021-03-R-win32-x86_64/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/D:/eclipse-jee-2021-03-R-win32-x86_64/eclipse/configuration/org.eclipse.osgi/6/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/eclipse-jee-2021-03-R-win32-x86_64/eclipse/plugins/org.eclipse.m2e.maven.runtime.slf4j.simple_1.16.0.20200610-1735/jars/slf4j-simple-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [file:/D:/eclipse-jee-2021-03-R-win32-x86_64/eclipse/configuration/org.eclipse.osgi/6/0/.cp/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------< com.edu:MavenProject2024 >----------------------
[INFO] Building MavenProject2024 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- jacoco-maven-plugin:0.8.7:prepare-agent (prepare-agent) @ MavenProject2024 ---
[INFO] argLine set to -javaagent:C:\\Users\\86135\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.8.7\\org.jacoco.agent-0.8.7-runtime.jar=destfile=D:\\eclipse-workSpace\\MavenProject2024\\target\\jacoco.exec
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ MavenProject2024 ---
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ MavenProject2024 ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding GBK, i.e. build is platform dependent!
[INFO] Compiling 6 source files to D:\eclipse-workSpace\MavenProject2024\target\classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.592 s
[INFO] Finished at: 2024-11-20T16:03:01+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project MavenProject2024: Fatal error compiling: 错误: 无效的目标发行版:15.0.2 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

1、对于第一个错误信息 “SLF4J: Class path contains multiple SLF4J bindings” :

表示项目类路径中包含了多个SLF4J(Simple Logging Facade for Java)的绑定实现。SLF4J是一个用于日志管理的门面,它允许使用统一的接口来调用各种日志框架。但是当项目的类路径上有多个SLF4J的实现时,它不知道应该使用哪一个,因此会给出警告。

查看报错提示,可以发现错误的具体信息如下:

  • 有两个SLF4J的绑定:
    • 一个位于Eclipse插件的目录下:slf4j-simple-1.7.5.jar
    • 另一个位于Eclipse配置的OSGi框架中:org/slf4j/impl/StaticLoggerBinder.class

解决这个问题的方法通常有以下几种:

  1. 排除冲突的依赖:在Maven的pom.xml文件中,可以排除掉那些包含SLF4J绑定的依赖项。找到引入了多个SLF4J绑定的依赖,并使用<exclusions>标签排除它们。

  2. 使用依赖管理:在pom.xml中使用<dependencyManagement>来确保只使用一个版本的SLF4J绑定。

  3. shade插件:如果无法通过排除依赖来解决冲突,可以使用Maven的shade插件来重新打包你的应用程序,并排除掉不需要的绑定。

2、对于第二个错误信息“无效的目标发行版:15.0.2”,这通常表示项目指定的Java编译版本不正确或不可用。

  1. 检查Java版本:确保Eclipse环境中配置的JDK版本是正确的,并且项目的pom.xml文件中的maven-compiler-plugin配置的sourcetarget版本与设置的JDK版本兼容。

  2. 更新Maven插件:确保maven-compiler-plugin是最新版本,并且配置正确。

  3. 检查Eclipse设置:在Eclipse中,检查项目的构建路径(Build Path)设置,确保指向正确的JDK。

3、这里的解决方法就是去设置编译器插件和排除SLF4J绑定:

<project>
    ...
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source> <!-- 根据自己设置的JDK版本来设置 -->
                    <target>1.8</target> <!-- 根据自己设置的JDK版本来设置 -->
                </configuration>
            </plugin>
            <!-- 排除SLF4J绑定 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>analyze</id>
                        <goals>
                            <goal>analyze-only</goal>
                        </goals>
                        <configuration>
                            <failOnWarning>true</failOnWarning>
                            <ignoreNonCompile>true</ignoreNonCompile>
                            <usedDependencies>
                                <usedDependency>org.slf4j:slf4j-api</usedDependency>
                            </usedDependencies>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    ...
</project>

4、最后执行mvn clean,清理一下再去执行要执行的命令,一般就ok了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值