简体   繁体   English

从 maven 中央隔离 maven jar 依赖项不可用

[英]Isolate maven jar dependencies that are unavailable from maven central

I am attempting to refactor a maven build process, and I am trying to populate a local maven repository to help with this refactor.我正在尝试重构 maven 构建过程,并且我正在尝试填充本地 maven 存储库以帮助进行此重构。

My build depends on obsolete versions of jar files that exist only in a maven repo on my network (not in maven central).我的构建取决于 jar 文件的过时版本,这些文件仅存在于我的网络上的 maven 存储库中(不在 maven 中心)。 Example: org.foo:example:1.7:jar示例:org.foo:example:1.7: org.foo:example:1.7:jar

I have been attempting to run my maven build in a docker image image with the hope that I could identify all of the obsolete components being pulled from my maven repository.我一直在尝试在 docker 映像中运行我的 maven 构建,希望我可以识别从我的 maven 存储库中提取的所有过时组件。

My goal is to explicitly pull down dependencies from my maven repo and then build the application using only maven central as an external repository.我的目标是从我的 maven 存储库中显式下拉依赖项,然后仅使用 maven 中央作为外部存储库构建应用程序。

I have a docker file to run the build我有一个 docker 文件来运行构建

FROM maven:3-jdk-8 as build

WORKDIR /build

# This pom.xml file only references maven central.
COPY pom.xml .

# Explicitly download artifacts into /root/.m2/...

RUN mvn dependency:get -Dartifact=org.foo:example:1.7.jar \
  -DrepoUrl=https://my.maven.repo

# Run the build making use of the dependencies loaded into the local repo
RUN mvn install

Unfortunately, I see an error: could not resolve dependencies for project... The following artifacts could not be resolved: org.foo:example:jar:1.7 .不幸的是,我看到一个错误: could not resolve dependencies for project... The following artifacts could not be resolved: org.foo:example:jar:1.7

I presume there might be some metadata in my local org.foo:example:1.7:pom that has an awareness of its origin repository.我认为我的本地 org.foo:example:1.7:pom 中可能有一些元数据,它们知道其原始存储库。 I had hoped I could satisfy this dependency by pulling it into my local repository.我曾希望通过将其拉入本地存储库来满足这种依赖关系。

I also attempted to add the following flag我还尝试添加以下标志

RUN mvn install --no-snapshot-updates

After further investigation, I discovered that the downloads in my.m2/repository contained files named _remote.repositories .经过进一步调查,我发现 my.m2/repository 中的下载包含名为_remote.repositories的文件。

Solution: set -Dmaven.legacyLocalRepo=true when running dependency:get解决方案:运行dependency:get时设置-Dmaven.legacyLocalRepo=true

With this flag, the _remote.repositories files are not created.使用此标志,不会创建_remote.repositories文件。

RUN mvn dependency:get -Dmaven.legacyLocalRepo=true \
  -Dartifact=org.foo:example:1.7.jar \
  -DrepoUrl=https://my.maven.repo

This question helped to provide a solution: _remote.repositories prevents maven from resolving remote parent这个问题有助于提供解决方案: _remote.repositories prevent maven from resolve remote parent

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM