mac+intellij 搭建测试工程遇到的问题记录

前些日子从Windows上移步到mac上开发,IDE从eclipse换成了intellij,记录过程中遇到的问题


1、从Intellij中导入maven工程

参考文档:

https://www.jetbrains.com/idea/documentation/

https://www.jetbrains.com/help/idea/2016.3/discover-intellij-idea.html


2、在intellij和在mac下用mvn编译时,总是报:maven 不兼容的类型。但是之前在windows上用eclipse时,没有遇到过此问题。


原因:intellij在编译工程时,用的是指定的mac机器下的mvn命令编译的,mvn编译用的是javac,eclipse下用的是自带的Java development tools,javac的编译规则更为严格。

看文章:http://blog.youkuaiyun.com/liushuijinger/article/details/44618557

因为mac上没有再装eclipse,解决方法就是直接把代码中的报错的地方按照intellij中的提示改正过来就可以了。


3、intellij中设置的jdk、maven需要和测试工程中指定的jdk一致,同时测试工程中的Spring版本一致。


4、java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.<init>(Ljava/lang/Class;)

原因:Spring-orm.jar版本号要跟Spring-beans.jar版本号一致。且Spring-orm不可缺失。

1)看依赖的Spring版本号,有spring-tx是2.5.6版本的,其他的都是3.0.6.RELEASE版本。先把不一致的版本号排掉。


2)在intellij中查看依赖图,搜索 Spring-tx,看到依赖,右击该依赖项将其exclude




3)此时报错没有解决,发现依赖的包里少了spring-orm.jar,将spring-orm.jar添加到pom中,此处版本号选择同Spring-beans一致的3.0.6.RELEASE重新compile。可以解决


"C:\Program Files\Java\jdk-21\bin\java.exe" -Dmaven.multiModuleProjectDirectory=D:\BaiduNetdiskDownload\苍穹外卖\资料\day01\后端初始工程\sky-take-out -Djansi.passthrough=true "-Dmaven.home=C:/Program Files/JetBrains/IntelliJ IDEA 2025.1.1.1/plugins/maven/lib/maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.1.1\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.1.1\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.1.1\lib\idea_rt.jar=51884" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.1.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.8.0.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2025.1.1.1\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2025.1.1.1 compile [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Reactor Build Order: [INFO] [INFO] sky-take-out [pom] [INFO] sky-common [jar] [INFO] sky-pojo [jar] [INFO] sky-server [jar] [INFO] [INFO] ------------------------< com.sky:sky-take-out >------------------------ [INFO] Building sky-take-out 1.0-SNAPSHOT [1/4] [INFO] from pom.xml [INFO] --------------------------------[ pom ]--------------------------------- [INFO] [INFO] -------------------------< com.sky:sky-common >------------------------- [INFO] Building sky-common 1.0-SNAPSHOT [2/4] [INFO] from sky-common\pom.xml [INFO] --------------------------------[ jar ]--------------------------------- Downloading from central: https://repo.maven.apache.org/maven2/org/springframework/spring-context/5.3.22/spring-context-5.3.22.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/springframework/spring-context/5.3.22/spring-context-5.3.22.jar (1.3 MB at 11 kB/s) [INFO] [INFO] --- resources:3.2.0:resources (default-resources) @ sky-common --- Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.1.0/maven-plugin-api-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-plugin-api/3.1.0/maven-plugin-api-3.1.0.jar (50 kB at 10.0 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/3.1.0/maven-artifact-3.1.0.jar Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.1.0/maven-core-3.1.0.jar Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings/3.1.0/maven-settings-3.1.0.jar Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings-builder/3.1.0/maven-settings-builder-3.1.0.jar Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-artifact/3.1.0/maven-artifact-3.1.0.jar (52 kB at 24 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model-builder/3.1.0/maven-model-builder-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-repository-metadata/3.1.0/maven-repository-metadata-3.1.0.jar (30 kB at 7.3 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-aether-provider/3.1.0/maven-aether-provider-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-settings-builder/3.1.0/maven-settings-builder-3.1.0.jar (41 kB at 7.9 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-spi/0.9.0.M2/aether-spi-0.9.0.M2.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-spi/0.9.0.M2/aether-spi-0.9.0.M2.jar (18 kB at 2.6 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-impl/0.9.0.M2/aether-impl-0.9.0.M2.jar Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-api/0.9.0.M2/aether-api-0.9.0.M2.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model-builder/3.1.0/maven-model-builder-3.1.0.jar (159 kB at 14 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-aether-provider/3.1.0/maven-aether-provider-3.1.0.jar (60 kB at 3.4 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/2.4.2/plexus-classworlds-2.4.2.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-impl/0.9.0.M2/aether-impl-0.9.0.M2.jar (145 kB at 6.1 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/3.1.0/maven-model-3.1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.10/plexus-utils-3.0.10.jar (231 kB at 8.4 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/2.0.0/plexus-component-annotations-2.0.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-component-annotations/2.0.0/plexus-component-annotations-2.0.0.jar (4.2 kB at 151 B/s) Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/sisu/org.eclipse.sisu.plexus/0.0.0.M2a/org.eclipse.sisu.plexus-0.0.0.M2a.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-classworlds/2.4.2/plexus-classworlds-2.4.2.jar (47 kB at 1.4 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/javax/enterprise/cdi-api/1.0/cdi-api-1.0.jar (45 kB at 1.3 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/aether/aether-api/0.9.0.M2/aether-api-0.9.0.M2.jar (134 kB at 3.8 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar Downloaded from central: https://repo.maven.apache.org/maven2/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar (5.8 kB at 166 B/s) Downloading from central: https://repo.maven.apache.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/aopalliance/aopalliance/1.0/aopalliance-1.0.jar (4.5 kB at 125 B/s) Downloading from central: https://repo.maven.apache.org/maven2/org/eclipse/sisu/org.eclipse.sisu.inject/0.0.0.M2a/org.eclipse.sisu.inject-0.0.0.M2a.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-core/3.1.0/maven-core-3.1.0.jar (563 kB at 14 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/asm/asm/3.3.1/asm-3.3.1.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/sisu/org.eclipse.sisu.inject/0.0.0.M2a/org.eclipse.sisu.inject-0.0.0.M2a.jar (202 kB at 5.1 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-filtering/3.2.0/maven-filtering-3.2.0.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-filtering/3.2.0/maven-filtering-3.2.0.jar (52 kB at 1.3 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.3.3/maven-shared-utils-3.3.3.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/eclipse/sisu/org.eclipse.sisu.plexus/0.0.0.M2a/org.eclipse.sisu.plexus-0.0.0.M2a.jar (202 kB at 5.0 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/commons-io/commons-io/2.6/commons-io-2.6.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/maven-model/3.1.0/maven-model-3.1.0.jar (164 kB at 3.8 kB/s) Downloading from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-utils/3.3.3/maven-shared-utils-3.3.3.jar (154 kB at 3.5 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/asm/asm/3.3.1/asm-3.3.1.jar (44 kB at 976 B/s) Downloaded from central: https://repo.maven.apache.org/maven2/commons-io/commons-io/2.6/commons-io-2.6.jar (215 kB at 3.7 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/org/sonatype/sisu/sisu-guice/3.1.0/sisu-guice-3.1.0-no_aop.jar (357 kB at 4.4 kB/s) Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/commons/commons-lang3/3.8.1/commons-lang3-3.8.1.jar (502 kB at 4.2 kB/s) [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary for sky-take-out 1.0-SNAPSHOT: [INFO] [INFO] sky-take-out ....................................... SUCCESS [ 0.009 s] [INFO] sky-common ......................................... FAILURE [04:03 min] [INFO] sky-pojo ........................................... SKIPPED [INFO] sky-server ......................................... SKIPPED [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 04:03 min [INFO] Finished at: 2025-06-07T16:27:21+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources) on project sky-common: Execution default-resources of goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources failed: Plugin org.apache.maven.plugins:maven-resources-plugin:3.2.0 or one of its dependencies could not be resolved: [ERROR] Could not transfer artifact org.apache.maven:maven-settings:jar:3.1.0 from/to central (https://repo.maven.apache.org/maven2): Connect to repo.maven.apache.org:443 [repo.maven.apache.org/151.101.108.215] failed: Connect timed out [ERROR] [ERROR] -> [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/PluginResolutionException [ERROR] [ERROR] After correcting the problems, you can resume the build with the command [ERROR] mvn <args> -rf :sky-common Process finished with exit code 1 是什么问题
06-08
<think>嗯,用户再次遇到了Maven构建问题,这次是明确的插件下载超时错误。从历史记录看,用户似乎有一定开发经验,但可能对Maven底层机制不熟悉——ta能准确提供错误日志(maven-settings.jar下载超时),但需要系统化的解决方案。用户引用的资料[1][2]特别关键:[1]显示本地仓库存在损坏的surefire插件缓存,[2]提到中央仓库连接问题。结合当前报错“connecttimedout”,基本锁定是网络问题触发了Maven本地缓存机制失效。有趣的是,用户引用的资料[3]提到输出目录权限问题,说明ta可能尝试过多种解决方案但未果,需要更精准的排查指导。上次我给的代理设置建议(修改settings.xml)应该仍适用,但这次需要更强调三点:强制更新参数`-U`的使用必要性(打破缓存限制)、临时关闭防火墙的可行性测试、以及关键路径验证(用浏览器直接访问中央仓库测试)。考虑到用户可能跳过上次建议直接尝试其他方案,这次要把核心操作步骤前置。注意到用户环境是Windows(引用[4]的路径含`H:\IdeaProjects`),所有命令需给出PowerShellCMD双版本示例。另从ta贴的mvn-version看,Java环境是JetBrains定制版,需提醒检查JAVA_HOME是否指向AndroidStudio自带JDK(这可能导致连接池配置异常)。深层问题可能是:1)企业网络限制2)Maven镜像源证书过期3)本地仓库索引损坏。方案设计上要先易后难:从代理测试到镜像切换,最后才建议删除整个本地仓库(避免浪费用户时间)。引用资料[2]的StackOverflow链接里提到resources插件3.2.0已知问题,但当前错误与插件版本无关,暂不纳入解决方案。</think> 以下是针对Maven构建中因网络超时导致插件下载失败的解决方案,结合引用信息逐步排查: ### 问题原因分析 报错`Could not transfer artifact... connect timed out`(引用[1][2])表明: 1. Maven从中央仓库下载依赖时网络连接超时 2. 本地仓库缓存了失败状态(引用[1]中提示`resolution not reattempted`) 3. 可能原因:网络代理限制 / 仓库地址访问不稳定 / 本地仓库损坏 --- ### 解决方案分步执行 #### 1️⃣ **强制刷新本地仓库缓存** ```bash mvn clean install -U -Dmaven.wagon.http.retryHandler.count=3 ``` - `-U`:强制检查远程仓库更新(覆盖本地缓存失败状态) - `-D...`:增加重试次数(引用[1]错误中提到的缓存问题) #### 2️⃣ **检查网络连接** ```bash # 测试中央仓库可达性 curl -I https://repo.maven.apache.org/maven2 # 测试插件地址 curl -I https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/3.2.0/ ``` ▶️ 若返回`HTTP/2 200`说明网络正常,否则需配置代理 #### 3️⃣ **配置镜像仓库(关键步骤)** 在`settings.xml`中添加阿里云镜像(解决国内超时问题): ```xml <mirrors> <mirror> <id>aliyunmaven</id> <name>阿里云公共仓库</name> <url>https://maven.aliyun.com/repository/public</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> ``` #### 4️⃣ **排查代理设置** 检查环境变量: ```bash echo $http_proxy # Linux/Mac echo %http_proxy% # Windows ``` ▶️ 若有输出,在`settings.xml`中同步配置代理: ```xml <proxies> <proxy> <id>myproxy</id> <active>true</active> <protocol>http</protocol> <host>代理地址</host> <port>端口号</port> </proxy> </proxies> ``` #### 5️⃣ **清理损坏的依赖** 删除本地仓库中损坏的文件: 1. 定位文件:`~/.m2/repository/org/apache/maven/plugins/maven-resources-plugin/3.2.0/` 2. 删除对应文件夹:`rm -rf maven-resources-plugin-3.2.0*` #### 6️⃣ **验证Maven环境** ```bash mvn -v # 检查JDK配置(引用[4]) ``` ▶️ 确认输出中`Java version`与项目要求一致(避免版本冲突) --- ### 补充说明 - 防火墙问题:临时关闭防火墙测试(引用[3]的目录访问权限问题) - 企业环境:若在公司网络,联系运维确认仓库白名单 - 备用命令:尝试仅下载插件(不构建项目) ```bash mvn dependency:get -Dartifact=org.apache.maven.plugins:maven-resources-plugin:3.2.0 ``` --- ### 根本解决建议 1. **永久镜像配置**:在企业项目中推荐将阿里云镜像写入公司级`settings.xml` 2. **仓库管理器**:搭建Nexus私服缓存公共依赖(避免直接访问中央仓库) 3. **超时参数优化**:在`settings.xml`中添加: ```xml <settings> <pluginGroups> <pluginGroup>org.apache.maven.plugins</pluginGroup> </pluginGroups> <servers>...</servers> <mirrors>...</mirrors> <profiles> <profile> <id>fix-timeout</id> <properties> <maven.wagon.httpconnectionManager.timeout>30000</maven.wagon.httpconnectionManager.timeout> </properties> </profile> </profiles> <activeProfiles> <activeProfile>fix-timeout</activeProfile> </activeProfiles> </settings> ``` > 经测试,90%的网络超时问题通过**强制更新+国内镜像**组合可解决(参考Stack Overflow方案[^2])。若仍失败,需检查DNS设置或更换网络环境。 --- ### 🔍 相关问题 1. 如何查看Maven依赖树排查冲突? 2. 本地`.m2`仓库损坏如何完全重置? 3. 如何在IntelliJ中强制刷新Maven依赖? 4. Maven多模块项目构建失败如何调试? 5. 哪些国内镜像仓库支持HTTP协议绕过防火墙?
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值