问题背景
项目生产环境因为各种原因,不允许访问maven仓库,只能将本地下载完成的仓库打包上传到服务器上。maven构建命令如下:
mvn clean package -Pprod -Dmaven.test.skip=true -o
其中-o
标识离线模式。同时也需要在maven的setting.xml文件中指定离线模式:
问题现象
报错信息如下:
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact com.fasterxml.jackson:jackson-bom:pom:2.10.0 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 629, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact io.micrometer:micrometer-bom:pom:1.3.1 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 1027, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact io.netty:netty-bom:pom:4.1.43.Final has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 1034, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact io.projectreactor:reactor-bom:pom:Dysprosium-SR1 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 1046, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact io.rsocket:rsocket-bom:pom:1.0.0-RC5 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 1108, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.apache.logging.log4j:log4j-bom:pom:2.12.1 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 1797, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.eclipse.jetty:jetty-bom:pom:9.4.22.v20191022 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 2105, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.glassfish.jersey:jersey-bom:pom:2.29.1 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 2239, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.jetbrains.kotlin:kotlin-bom:pom:1.3.50 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 2581, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.jetbrains.kotlinx:kotlinx-coroutines-bom:pom:1.3.2 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 2588, column 19 -> [Help 2]
[ERROR] Non-resolvable import POM: Cannot access nexus (http://maven.xxxyyy.com/nexus/content/groups/public/) in offline mode and the artifact org.junit:junit-bom:pom:5.5.2 has not been downloaded from it before. @ org.springframework.boot:spring-boot-dependencies:2.2.1.RELEASE, /mvnrepo/org/springframework/boot/spring-boot-dependencies/2.2.1.RELEASE/spring-boot-dependencies-2.2.1.RELEASE.pom, line 2615, column 19 -> [Help 2]
解决方案
在本地仓库根目录下,执行以下命令:
find . -name "_remote.repositories" | xargs rm
该命令会删除所有子目录下_remote.repositories
文件。
参考
https://*.com/questions/16866978/maven-cant-find-my-local-artifacts/16870552