Maven이 아티팩트를 검색하기 위해 원격 저장소로 이동하지 않고 로컬 저장소를 사용하도록 강제하는 방법은 무엇입니까?
Mac Yosemite에서 Java 8과 함께 Maven 3.3.3을 사용하고 있습니다. 다중 모듈 프로젝트가 있습니다.
<modules>
<module>first-module</module>
<module>my-module</module>
…
</modules>
"mvn clean install"을 사용하여 위의 "my-module"과 같은 자식 모듈 중 하나를 빌드 할 때 빌드는 내가 ~ / .m2에 정의한 원격 저장소에서 자식 모듈 아티팩트를 다운로드하려고 시도합니다. /settings.xml 파일. 출력은 다음과 같습니다.
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.9 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151104.200545-4.pom
원격 저장소에서 다운로드를 시도하기 전에 Maven이 내 로컬 ~ / .m2 / repository를 먼저 확인하도록 강제하는 방법은 무엇입니까? 아래는 ~ / .m2 / settings.xml 파일에 정의 된 원격 저장소가있는 곳입니다.
<profile>
<id>releases</id>
<activation>
<property>
<name>!releases.off</name>
</property>
</activation>
<repositories>
<repository>
<id>releases</id>
<url>https://my.remoterepository.com/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>snapshots</id>
<activation>
<property>
<name>!snapshots.off</name>
</property>
</activation>
<repositories>
<repository>
<id>snapshots</id>
<url>https://my.remoterepository.com/nexus/content/repositories/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
편집 : 아티팩트가 없을 때 다운로드가 발생한다는 답변에 대한 응답으로 아래는 파일이 내 저장소에 있음을 증명했지만 Maven이 어쨌든 다운로드를 시도하는 터미널 출력입니다 ...
Daves-MacBook-Pro-2:my-module davea$ ls -al ~/.m2/repository/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-SNAPSHOT.jar
-rw-r--r-- 1 davea staff 10171 Nov 5 10:22 /Users/davea/.m2/repository/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-SNAPSHOT.jar
Daves-MacBook-Pro-2:my-module davea$ mvn clean install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for org.mainco.subco:my-module:jar:87.0.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-antrun-plugin @ org.mainco.subco:my-module:[unknown-version], /Users/davea/Documents/sb_workspace/my-module/pom.xml, line 678, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building my-module 87.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: http://download.java.net/maven/2/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/maven-metadata.xml (788 B at 0.8 KB/sec)
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first-module-87.0.0-20151106.043202-8.pom
Downloaded: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/first-module/87.0.0-SNAPSHOT/first- module-87.0.0-20151106.043202-8.pom (3 KB at 21.9 KB/sec)
Downloading: http://download.java.net/maven/2/org/mainco/subco/subco/87.0.0-SNAPSHOT/maven-metadata.xml
Downloading: https://my.remoterepository.com/nexus/content/repositories/snapshots/org/mainco/subco/subco/87.0.0-SNAPSHOT/maven-metadata.xml
종속성에 스냅 샷 버전이 있습니다. 스냅 샷의 경우 Maven은 로컬 저장소를 확인하고 로컬 저장소에서 발견 된 아티팩트가 너무 오래된 경우 원격 저장소에서 업데이트 된 항목을 찾으려고 시도합니다. 그것은 아마도 당신이보고있는 것입니다.
이 동작은 updatePolicy
저장소 구성 의 지시문 ( daily
기본적으로 스냅 샷 저장소의 경우)에 의해 제어됩니다 .
사용 mvn --help
하면 옵션 목록을 볼 수 있습니다.
다음과 같은 옵션이 있습니다. -nsu,--no-snapshot-updates Suppress SNAPSHOT updates
따라서 명령 mvn install -nsu
을 사용하면 로컬 저장소로 강제 컴파일 할 수 있습니다.
To truly force maven to only use your local repo, you can run with mvn <goals> -o
. The -o
tells maven to let you work "offline", and it will stay off the network.
In my case I had a multi module project just like you. I had to change a group Id of one of the external libraries my project was depending on as shown below.
From:
<dependencyManagement>
<dependency>
<groupId>org.thirdparty</groupId>
<artifactId>calculation-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependencyManagement>
To:
<dependencyManagement>
<dependency>
<groupId>org.thirdparty.module</groupId>
<artifactId>calculation-api</artifactId>
<version>2.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependencyManagement>
Pay attention to the <groupId> section. It turned out that I was forgetting to modifiy the corresponding section of the submodules that define this dependency in their pom files.
It drove me very crazy because the module was available locally.
The -o option didn't work for me because the artifact is still in development and not yet uploaded and maven (3.5.x) still tries to download it from the remote repository because it's the first time, according to the error I get.
However this fixed it for me: https://maven.apache.org/general.html#importing-jars
After this manual install there's no need to use the offline option either.
UPDATE
I've just rebuilt the dependency and I had to re-import it: the regular mvn clean install
was not sufficient for me
Follow below steps:
1.Ensure to delete all the contents of the jar folder located in your local except the jar that you want to keep.
For example files like .repositories, .pom, .sha1, .lastUpdated etc.
2.Execute mvn clean install -o command
This will help to use local repository jar files rather than connecting to any repository.
Maven always checks your local repository first, however,your dependency needs to be installed in your repo for maven to find it.
Run mvn install
in your dependency module first, and then build your dependent module.
'Program Tip' 카테고리의 다른 글
중국어 간체 및 번체 vs 지역 (0) | 2020.11.02 |
---|---|
Django 및 Bootstrap : 어떤 앱을 권장합니까? (0) | 2020.11.02 |
Java에서 매우 반복적 인 코드 및 문서 관리 (0) | 2020.11.02 |
WeakReference로 청취자의 장단점 (0) | 2020.11.01 |
브라우저 간 (피어 투 피어) 연결을 어떻게 만들 수 있습니까? (0) | 2020.11.01 |