我需要使用 Jenkins 构建和发布项目,
在无法访问 maven central 甚至无法访问 Nexus 的服务器上。
鉴于我可以在开发机器上访问 maven-central,
填充 maven local_repository,我可以做
mvn dependency:resolve-plugins dependency:go-offline
然后在linux服务器上复制local_repository。
然后,乘坐
Non-resolvable parent POM
错误,如所述 here ,我用伪造的中央配置文件填充了 windows (dev) 和 linux (jenkins) 的特定配置文件,以覆盖我的父 pom 所做的 maven-central 引用:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>Windows</family>
</os>
</activation>
<properties> <repository.base.url>file:///c:/maven_distribution_repo/</repository.base.url>
</properties>
</profile>
<profile>
<id>linux</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>
</properties>
<repositories>
<repository>
<id>central</id>
<name>Maven Plugin Repository</name>
<!--<url>http://repo1.maven.org/maven2</url>-->
<url>${repository.base.url}</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Maven Plugin Repository</name>
<!--<url>http://repo1.maven.org/maven2</url>-->
<url>${repository.base.url}</url>
<layout>default</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
这样,
mvn -o compile
还是提个Non-resolvable parent POM
错误 !,但使用
--legacy-local-repository
建议选项 here ,设法使用本地存储库伪造远程存储库,
和
Non-resolvable parent POM
问题消失:mvn --legacy-local-repository 编译
尽管如此,还是出现了一个奇怪的错误(描述为 here):
[ERROR] Failed to execute goal on project myProject: Could not resolve dependencies for project some.package:myProject:war:0.0.7-SNAPSHOT: Failed to collect dependencies at org.jxls:jxls-poi:jar:1.0.11 -> org.jxls:jxls:jar:[2.0.0,): org.jxls:jxls:jar:[2.0.0,) within specified range -> [Help 1]
但它隐藏了更早的警告:
[WARNING] Could not transfer metadata org.jxlsjxls/maven-metadata.xml from/to central (/path):/appli/Maven_3.1.1_build/maven_distribution_repo/org/jxls/jxls/maven-metadata-central.xml (access forbidden)
使用 --legacy-local-repository,maven 似乎使用分发存储库路径作为本地 libs 存储库!
我在 pom 中交换了它们:
<profile>
<id>linux</id>
<activation>
<os>
<family>Linux</family>
</os>
</activation>
<properties>
<!--<repository.base.url>file:///appli/Maven_3.1.1_build/maven_distribution_repo/</repository.base.url>-->
<repository.base.url>file:///appli/Maven-3.1.1_build/maven_local_repo/</repository.base.url>
</properties>
...
并且还必须复制到本地存储库中:
全部
maven-metadata-maven2_central.xml
进入 maven-metadata.xml
使用以下 bash 命令:
for file in $(find /appli/Maven-3.1.1_build/maven_local_repo -type f -name 'maven-metadata-maven2_central.xml'); do cp $file $(echo ${file%/*}/maven-metadata.xml); done
还有……宾果游戏!
搭建成功
看起来很奇怪,在后期,到
release:perform
到本地 lib 存储库。你有更好的而不是那种痛苦的解决方案吗?
最佳答案
Maven 部署插件可以解决这个问题。
mvn deploy -DaltDeploymentRepository=local-temp::default::file://directory/
更详尽的例子:
# 1. Create temporary folder
tmp_repo=$(mktemp -d systemds-repo-tmp-XXXXX)
# 2. Create a simple settings.xml
cat <<EOF >../tmp-settings-nexus.xml
<settings>
<activeProfiles>
<activeProfile>local-temp</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>local-temp</id>
<repositories>
<repository>
<id>local-temp</id>
<url>${tmp_repo}</url>
</repository>
</repositories>
</profile>
</profiles>
</settings>
EOF
# 3. deploy to local
mvn --settings ../tmp-settings-nexus.xml -Pdistribution deploy \
-DaltDeploymentRepository=local-temp::default::file://${tmp_repo} \
-Daether.checksums.algorithms='SHA-512,SHA-1,MD5'
关于maven - 如何从离线机器构建和发布 Maven 项目(文件目录为 lib-repository),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43661755/