在IntelliJ IDEA中构建maven项目的时,出现了报错:ArchetypeDataSourceException
一,报错具体信息:
[WARNING] failed to download from remote org.apache.maven.archetype.source.ArchetypeDataSourceException: org.eclipse.aether.transfer.MetadataNotFoundException: Could not find metadata /archetype-catalog.xml in aliyunmaven (https://maven.aliyun.com/repository/public)
二,报错分析
报错:“failed to download from remote org.apache.maven.archetype.source.ArchetypeDataSourceException” 的原因是因为随机书写了一个archetype,如图所示,在IntelliJ IDEA2024中这样书写archetype进行创建是不正确的。
可按照自己定义的坐标设置应该在红框位置进行设定
archetype不是提供给开发人员进行随意书写的地方,Maven 在创建项目时,会尝试从远程仓库中下载指定的 archetype,如果这个 archetype 不存在或者填写不正确,就会出现 “failed to download from remote” 这样的错误。
常用的 Maven Archetype
- maven-archetype-quickstart:最基础的 Maven 项目模板,包含一个简单的 Java 项目结构(src/main/java 和 src/test/java)。
- Group Id:
org.apache.maven.archetypes
- Artifact Id:
maven-archetype-quickstart
- Group Id:
- maven-archetype-webapp:适用于创建 Web 应用程序的基础结构,包含
src/main/webapp
和WEB-INF
目录。- Group Id:
org.apache.maven.archetypes
- Artifact Id:
maven-archetype-webapp
- Group Id:
- maven-archetype-archetype:一个通用的项目模板,用于创建你自己的 Maven archetype(项目模板)。
- Group Id:
org.apache.maven.archetypes
- Artifact Id:
maven-archetype-archetype
- Group Id:
- spring-boot-sample-data-jpa(适用于 Spring Boot 项目):创建包含 Spring Boot 和 JPA 配置的项目结构。
- Group Id:
org.springframework.boot
- Artifact Id:
spring-boot-sample-data-jpa
- Group Id:
三,解决方案
设定正确的Maven Archetype,在Advanced Settings处设定Maven项目的坐标信息
如果设定了正确的 ,出现了警告,警告内容为:
[WARNING] failed to download from remote
org.apache.maven.archetype.source.ArchetypeDataSourceException: org.eclipse.aether.transfer.MetadataNotFoundException: /archetype-catalog.xml was not found in https://maven.aliyun.com/repository/public during a previous attempt. This failure was cached in the local repository and resolution is not be reattempted until the update interval of aliyunmaven has elapsed or updates are forced
of aliyunmaven has elapsed or updates are forced
其实主要的警告是 Maven 无法从阿里云镜像下载 archetype-catalog.xml
文件,导致 Archetype 的选择出现问题。由于项目已经成功创建,且只是一些仓库访问的警告信息,这些警告并不影响项目的实际构建。可以选择忽略这些警告,继续使用项目。