Maven可解析其他依赖却无法解析Xerces依赖问题咨询
Maven无法解析Xerces依赖问题排查与解决
我的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>org.example</groupId> <artifactId>xml-parsing</artifactId> <version>1.0-SNAPSHOT</version> <name>xml-parsing</name> <!-- FIXME change it to the project's website --> <url>https://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.xerces</groupId> <artifactId>org.apache.xerces</artifactId> <version>2.12.2</version> </dependency> </dependencies> <build> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> <plugin> <artifactId>maven-site-plugin</artifactId> <version>3.7.1</version> </plugin> <plugin> <artifactId>maven-project-info-reports-plugin</artifactId> <version>3.0.0</version> </plugin> </plugins> </pluginManagement> </build> </project>
执行mvn clean install时出现以下错误:
Failed to execute goal on project xml-parsing: Could not resolve dependencies for project org.example:xml-parsing:jar:1.0-SNAPSHOT: The following artifacts could not be resolved: org.apache.xerces:org.apache.xerces:jar:2.12.2, org.apache.xerces:xml-apis:jar:2.11.0-20110622: Could not find artifact org.apache.xerces:org.apache.xerces:jar:2.12.2 in central (https://repo.maven.apache.org/maven2)
已尝试的操作:
- 添加另一组groupId为org.apache.xerces的依赖,仍无法解析;
- 添加apache-commons依赖,可正常解析。
需要了解问题原因及解决方法。
问题原因
你配置的org.apache.xerces:org.apache.xerces:2.12.2这个构件不在Maven中央仓库中。中央仓库里Xerces的标准artifactId并非org.apache.xerces,而是xercesImpl,对应的依赖结构也有区别。
解决方法
将原有的Xerces依赖替换为中央仓库中存在的正确配置:
<dependency> <groupId>xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.2</version> </dependency>
或者如果偏好使用org.apache.xerces作为groupId,可使用以下配置:
<dependency> <groupId>org.apache.xerces</groupId> <artifactId>xercesImpl</artifactId> <version>2.12.2</version> </dependency>
替换完成后重新执行mvn clean install,Maven即可正常解析该依赖。
内容的提问来源于stack exchange,提问作者pensee
相关产品推荐
相关产品推荐

