简体   繁体   English

Maven:如何将依赖的工件提取(而不是解压缩)到本地存储库中的单独文件夹中

[英]Maven: How to extract (not unpack) dependent artifacts to a separate folder from local repository

Scenario: I need to prepare a usable and concise local repository for another developer who can't access maven public repository via network. 场景:我需要为另一个无法通过网络访问Maven公共存储库的开发人员准备一个可用且简洁的本地存储库。 But the local repository on my computer is about 20G which contains a large part of artifacts that is not relevant to the project. 但是我计算机上的本地存储库约为20G,其中包含与项目无关的大部分工件。

AFAIK I can use mvn dependency:resolve to download only the dependencies to a new local repository location but the network traffic is limited and I don't want to waste time waiting for the download to complete. AFAIK我可以使用mvn dependency:resolve将依赖项仅下载到新的本地存储库位置,但是网络流量有限,我不想浪费时间等待下载完成。 I googled a while and I tried dependency:copy-dependencies but it only copies the jar file, not including the pom.xml files and other meta-files in the artifact. 我用dependency:copy-dependencies歌搜索了一段时间,然后尝试了dependency:copy-dependencies但是它仅复制jar文件,而不包含工件中的pom.xml文件和其他元文件。

I know this work-around is kind of against the maven spirit, but sometimes we all need to work offline. 我知道这种解决方法有点违背行家精神,但有时我们所有人都需要脱机工作。

If you have a list of all the jars, you can extract them, temporarily mv .m2, install them as per https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html , give your colleague your local .m2 and rename your old .m2 back. 如果您有所有jar的列表,则可以提取它们,暂时将其mv .m2安装,并按照https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html进行安装,给您的同事您当地的.m2,然后重命名您的旧.m2。

Although rarely, but sometimes you will have 3rd party JARs that you need to put in your local repository for use in your builds, since they don't exist in any public repository like Maven Central. 尽管很少见,但有时您会需要将第3方JAR放到本地存储库中以在构建中使用,因为它们在Maven Central等任何公共存储库中都不存在。 The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Apache Maven. 必须将JAR放置在本地存储库中的正确位置,以便Apache Maven可以正确拾取JAR。 To make this easier, and less error prone, we have provide a goal in the maven-install-plugin which should make this relatively painless. 为了使此操作更容易且不易出错,我们在maven-install-plugin中提供了一个目标,该目标应使此工作相对简单。 To install a JAR in the local repository use the following command: 要在本地存储库中安装JAR,请使用以下命令:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

If there's a pom-file as well, you can install it with the following command: 如果还有pom文件,则可以使用以下命令进行安装:

mvn install:install-file -Dfile=<path-to-file> -DpomFile=<path-to-pomfile>

With version 2.5 of the maven-install-plugin it gets even better. 使用2.5版的maven-install-plugin会变得更好。 If the JAR was built by Apache Maven, it'll contain a pom.xml in a subfolder of the META-INF directory, which will be read by default. 如果JAR是由Apache Maven构建的,则它将在META-INF目录的子文件夹中包含pom.xml,默认情况下将读取该子文件夹。 In that case, all you need to do is: 在这种情况下,您需要做的只是:

mvn install:install-file -Dfile=<path-to-file>

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

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