오프라인 개발을 위해 Maven을 어떻게 구성합니까?
Maven을 사용하려면 어느 시점에서 인터넷 연결이 필요합니까? 컴파일, 정리, 패키징 등을 위해 내부 Maven 플러그인을 얻는 것을 의미합니까?
오프라인 모드에서 maven을 실행할 수 있습니다 mvn -o install
. 물론 로컬 저장소에서 사용할 수없는 아티팩트는 실패합니다. Maven은 분산 리포지토리를 기반으로하지 않지만 확실히 더 원활하게 만듭니다. 이러한 이유로 많은 상점에서 중앙 저장소와 점진적으로 동기화되는 내부 미러를 사용합니다.
또한 mvn dependency:go-offline
오프라인 작업을 시작하기 전에 모든 종속성이 로컬로 설치되었는지 확인하는 데 사용할 수 있습니다.
LAN에 인터넷 액세스가 가능한 PC가있는 경우 로컬 Maven 저장소를 설치해야합니다.
Artifactory Open Source를 추천 합니다. 이것은 우리가 조직에서 사용하는 것이며 설정하기가 정말 쉽습니다.
Artifactory는 빌드 도구 (Maven, Ant, Ivy, Gradle 등)와 외부 세계 간의 프록시 역할을합니다.
원격 아티팩트를 캐시하므로 반복해서 다운로드 할 필요가 없습니다.
내부 아티팩트에 대한 원치 않는 (때로는 보안에 민감한) 외부 요청을 차단하고 아티팩트를 배포하는 방법과 위치, 사용자를 제어합니다.
Artifactory를 설정 한 후 settings.xml
개발 머신에서 Maven을 변경하기 만하면됩니다 .
<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd" xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<mirrors>
<mirror>
<mirrorOf>*</mirrorOf>
<name>repo</name>
<url>http://maven.yourorganization.com:8081/artifactory/repo</url>
<id>repo</id>
</mirror>
</mirrors>
<profiles>
<profile>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>libs-release</name>
<url>http://maven.yourorganization.com:8081/artifactory/libs-release</url>
</repository>
<repository>
<snapshots />
<id>snapshots</id>
<name>libs-snapshot</name>
<url>http://maven.yourorganization.com:8081/artifactory/libs-snapshot</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>plugins-release</name>
<url>http://maven.yourorganization.com:8081/artifactory/plugins-release</url>
</pluginRepository>
<pluginRepository>
<snapshots />
<id>snapshots</id>
<name>plugins-snapshot</name>
<url>http://maven.yourorganization.com:8081/artifactory/plugins-snapshot</url>
</pluginRepository>
</pluginRepositories>
<id>artifactory</id>
</profile>
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>
개발 시스템에서 인터넷 액세스에 문제가 있고 일부 아티팩트가 손상된 파일을 다운로드했거나 전혀 다운로드하지 않았기 때문에이 솔루션을 사용했습니다. 그 이후로 문제가 없었습니다.
이에 대한 두 가지 옵션이 있습니다.
1.) make changes in the settings.xml add this in first tag
<localRepository>C:/Users/admin/.m2/repository</localRepository>
2.) use the -o tag for offline command.
mvn -o clean install -DskipTests=true
mvn -o jetty:run
Maven needs the dependencies in your local repository. The easiest way to get them is with internet access (or harder using other solutions provided here).
So assumed that you can get temporarily internet access you can prepare to go offline using the maven-dependency-plugin with its dependency:go-offline goal. This will download all your project dependencies to your local repository (of course changes in the dependencies / plugins will require new internet / central repository access).
Sadly
dependency:go-offline
hasn't worked for me as it didn't cached everything, ie. POMs files and other implicitly mention dependencies.
The workaround has been to specify a local repository location, either within settings.xml
file with <localRepository>...</localRepository>
or by running mvn
with -Dmaven.repo.local=...
parameter. After initial project build, all necessary artifacts should be cached, and then you can reference repository location the same ways, while running Maven build in offline mode (mvn -o ...
).
Before going offline you have to make sure that everything is in your local repo, which is required while working offline. Running "mvn dependency:go-offline" for the project(s)/pom(s), you intend to work on, will reduce the efforts to achieve this.
But it´s usually not the whole story, because dependency:go-offline will only download the "bare build" plugins (go-offline / resolve-plugins does not resolve all plugin dependencies). So you have to find a way to download deploy / test / site plugins (and maybe others) and their dependencies into your repo.
Furthermore dependency:go-offline does not download the pom´s artifact itself, so you have to dependency:copy it if required.
Sometimes - as MaDa wrote - you do not know, what you will need, while being offline, which makes it pretty impossible to have a "sufficient" repo.
Anyway having a properly filled repo you only have to add "<offline>true</offline>" to Maven´s settings.xml to go offline.
Do not change the Maven profile (id) you used to fill your repo, while being offline. Maven recognizes the downloaded artifacts in its metadata with an "identity", which is bound to the profile id.
Does this work for you?
http://jojovedder.blogspot.com/2009/04/running-maven-offline-using-local.html
Don't forget to add it to your plugin repository and point the url to wherever your repository is.
<repositories>
<repository>
<id>local</id>
<url>file://D:\mavenrepo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>local</id>
<url>file://D:\mavenrepo</url>
</pluginRepository>
</pluginRepositories>
If not, you may need to run a local server, e.g. apache, on your machines.
If you're using IntelliJ, you can simply go to Preferences -> Build, Execution, Deployment -> Build Tools -> Maven and check/uncheck Work offline.
(source: jfrog.com)
or
Just use Maven repository servers like Sonatype Nexus http://www.sonatype.org/nexus/ or JFrog Artifactory https://www.jfrog.com/artifactory/.
After one developer builds a project, build by next developers or Jenkins CI will not require Internet access.
Maven repository server also can have proxies configured to access Maven Central (or more needed public repositories), and they can have cynch'ed list of artifacts in remote repositories.
Answering your question directly: it does not require an internet connection, but access to a repository, on LAN or local disk (use hints from other people who posted here).
If your project is not in a mature phase, that means when POMs are changed quite often, offline mode will be very impractical, as you'll have to update your repository quite often, too. Unless you can get a copy of a repository that has everything you need, but how would you know? Usually you start a repository from scratch and it gets cloned gradually during development (on a computer connected to another repository). A copy of the repo1.maven.org public repository weighs hundreds of gigabytes, so I wouldn't recommend brute force, either.
In preparation before working offline just run mvn dependency:go-offline
My experience shows that the -o option doesn't work properly and that the go-offline goal is far from sufficient to allow a full offline build:
The solution I could validate includes the use of the --legacy-local-repository
maven option rather than the -o
(offline) one and the use of the local repository in place of the distribution repository
In addition, I had to copy every maven-metadata-maven2_central.xml
files of the local-repo into the maven-metadata.xml
form expected by maven.
See the solution I found here.
참고URL : https://stackoverflow.com/questions/7233328/how-do-i-configure-maven-for-offline-development
'Programming' 카테고리의 다른 글
노드 영구 / usr / bin / env : node : 해당 파일 또는 디렉토리 없음 (0) | 2020.08.08 |
---|---|
복사 생성자와 Clone () (0) | 2020.08.07 |
Jest 테스트를 순차적으로 실행하는 방법은 무엇입니까? (0) | 2020.08.07 |
cmd.exe에서 영구 환경 변수 설정 (0) | 2020.08.07 |
Bootstrap 3에서 반응 형 그리드를 얻는 방법은 무엇입니까? (0) | 2020.08.07 |