maven系列--错误解决

Dependency 'xxx:yyy:' not found

问题:在使用SpringCloud时,用到“spring-cloud-config-server”依赖,但发现它是红色的,鼠标放上去提示:“Dependency 'org.springframework.cloud:spring-cloud-config-server:' not found”,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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>config-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
    </dependencies>
</project>

分析

找到maven仓库路径里的spring-cloud-config-server包(所在路径:org\springframework\cloud\spring-cloud-config-server),发现里边只有一个unknown文件夹,正常来说,应该是以某个版本名为文件夹名,例如:2.0.1.RELEASE

原因

没有指定版本号

解决方法

1.删除unknown文件夹

2.指定spring-cloud-config-server的版本号
    本处通过指定spring-cloud-dependencies的版本号来指定spring-cloud的所有依赖,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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>config-server</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>config-server</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Finchley.SR1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

总结

        查看spring-cloud-dependencies所在路径:org\springframework\cloud\spring-cloud-dependencies\,发现里边有文件夹:Finchley.SR1,其里边有三个文件:_remote.repositories、spring-cloud-dependencies-Finchley.SR1.pom、spring-cloud-dependencies-Finchley.SR1.pom.sha1。

        查看spring-cloud-dependencies-Finchley.SR1.pom,发现它里边包括了所有SpringCloud的依赖。

archetype-catalog.xml

问题:创建Maven项目速度慢问题 或者 “No archetype found in remote catalog. Defaulting to internal catalog”

解决方法:

步骤1:下载archtype-catalog.xml

官网:https://repo1.maven.org/maven2/archetype-catalog.xml(打开速度很慢,打开后右键另存为即可)
国内网址:本人已把最新的上传到csdn。正在审核,成功后会放链接。

步骤2:将archetype-catalog.xml放到maven路径下

    我的仓库路径为:E:\work\maven\apache-maven-3.6.3\repository
    放置路径为:E:\work\maven\apache-maven-3.6.3\repository\
    (有的版本放到:E:\work\maven\apache-maven-3.6.3\repository\org\apache\maven\archetype\archetype-catalog\3.1.2\)

步骤3:在IDEA中设置archetype的使用方式为local;

     File=> Other Settings=> Setting for New Projects=> Build,Execution,Deployment=> Build Tools=> Maven=> Runner=> 
           VM Options=> 填写为“-DarchetypeCatalog=local”

注意:也可直接将archetypeCatalog指定为internal而不需要archtype-catalog.xml文件,此法不推荐。
    设置当前module(只能用internal)
          创建新Module到maven路径、配置文件这一步时,下边有个“Properties”=> groupId, archtypegroupId等,
          在下边新建一项:键为:archetypeCatalog,值为:internal。

问题rt 代码如下: ![图片说明](https://img-ask.csdn.net/upload/201906/12/1560350057_455880.png) ![图片说明](https://img-ask.csdn.net/upload/201906/12/1560350062_430379.png) ``` <?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> <!-- 从spring-boot-starter-parent继承版本号 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.5.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.manning</groupId> <artifactId>readinglist</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Reading List</name> <description>Reading List Demo</description> <properties> <java.version>1.8</java.version> </properties> <!-- 起步依赖 --> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <!-- maven构建插件 --> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> ```
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页