简体   繁体   中英

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.

My build depends on obsolete versions of jar files that exist only in a maven repo on my network (not in maven central). Example: 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.

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.

I have a docker file to run the build

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 .

I presume there might be some metadata in my local org.foo:example:1.7:pom that has an awareness of its origin repository. 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 .

Solution: set -Dmaven.legacyLocalRepo=true when running dependency:get

With this flag, the _remote.repositories files are not created.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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