MAVEN 无法解决依赖关系 [重复]
Posted
技术标签:
【中文标题】MAVEN 无法解决依赖关系 [重复]【英文标题】:MAVEN couldn't resolve the dependencies [duplicate] 【发布时间】:2020-08-27 11:57:58 【问题描述】:我正在开发一个在 Tomcat 上运行的基于 Maven 的 Web 应用程序。
我正在尝试将 log4j2
依赖项添加到我的 maven 项目中。但是,当我尝试构建我的项目时,底部的错误会发生。我尝试在本地安装 log4j
依赖项,但是我也无法让它工作。我想重新安装 Maven,但不知何故我只能停用它。如果您需要更多信息,请告诉我,以便我提供。
我尝试构建项目时的输出:
cd C:\...\Blockchain; "JAVA_HOME=C:\\Program Files\\Java\\jdk1.8.0_161" cmd /c "\"\"C:\\Program Files\\NetBeans 8.2\\java\\maven\\bin\\mvn.bat\" -Dmaven.ext.class.path=\"C:\\Program Files\\NetBeans 8.2\\java\\maven-nblib\\netbeans-eventspy.jar\" -Dfile.encoding=UTF-8 install\""
Scanning for projects...
------------------------------------------------------------------------
Building Blockchain 1.0-SNAPSHOT
------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/log4j-core/2.13.0/log4j-core-2.13.0.pom
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.069s
Finished at: Mon May 11 21:50:01 CEST 2020
Final Memory: 8M/123M
------------------------------------------------------------------------
Failed to execute goal on project Blockchain: Could not resolve dependencies for project com.bowolfcoin:Blockchain:war:1.0-SNAPSHOT: Failed to collect dependencies for [com.owlike:genson:jar:1.5 (compile), org.apache:log4j-core:jar:2.13.0 (compile), javax:javaee-web-api:jar:7.0 (provided), org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23 (compile), org.apache.tomcat:tomcat-jasper:jar:8.5.23 (compile), org.glassfish.jersey.containers:jersey-container-servlet:jar:2.0 (compile), org.bouncycastle:bcpkix-jdk15on:jar:1.56 (compile)]: Failed to read artifact descriptor for org.apache:log4j-core:jar:2.13.0: Could not transfer artifact org.apache:log4j-core:pom:2.13.0 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/log4j-core/2.13.0/log4j-core-2.13.0.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]
To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.
For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
这里是完整的 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>
<groupId>com.bowolfcoin</groupId>
<artifactId>Blockchain</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Blockchain</name>
<properties>
<tomcat.version>8.5.23</tomcat.version>
<endorsed.dir>$project.build.directory/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>1.5</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>$tomcat.version</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper</artifactId>
<version>$tomcat.version</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.56</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<endorseddirs>$endorsed.dir</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>$endorsed.dir</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
我现在能够构建项目。但是,当我尝试创建 Logger 对象时出现以下错误。在以下代码中,getLogger() 函数带有红色下划线,并带有以下错误文本:
代码:
package com.blockchain.api.services;
import com.blockchain.logic.DependencyManager;
import com.blockchain.logic.PendingTransactions;
import com.blockchain.models.Block;
import com.blockchain.models.Transaction;
import com.blockchain.utils.SHA3Helper;
import org.apache.logging.log4j.core.Logger;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
/**
*
* @author Bongi
*/
@Path("transactions")
public class TransactionService
private static Logger logger = Logger.getLogger(Transaction.class);
错误
cannot find symbol
symbol: method getLogger(Class<Transaction>)
location: class Logger
【问题讨论】:
我也有类似的问题。我不得不为几个依赖项排除一些库。 Gradle config 但也许它会帮助 compile(group: 'commons-logging', name: 'commons-logging-api', version: '1.1') exclude(module: 'servlet-api') compile (group: ' org.apache.commons',名称:'commons-dbcp2',版本:'2.2.0')排除(模块:'commons-logging') 您尝试使用 http 从存储库下载,但您需要 https。您是否在 pom 或设置中添加了存储库标签? 你必须使用https而不是http ....已更改blog.sonatype.com/central-repository-moving-to-https 添加完整的pom.xml
文件以检查存储库和依赖项标签。如果它有一个父 pom,请检查它的存储库。
@Christian 我还没有添加存储库标签。但是,当我尝试添加它们时,该项目仍会尝试从同一地址下载依赖项。
【参考方案1】:
您的日志记录工件似乎不正确。你可以试试这个:
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
您可以在此处确认此路径: https://repo.maven.apache.org/maven2/org/apache/logging/log4j/log4j-core/2.13.0/
另见: https://logging.apache.org/log4j/2.x/maven-artifacts.html
【讨论】:
以上是关于MAVEN 无法解决依赖关系 [重复]的主要内容,如果未能解决你的问题,请参考以下文章