How can I deploy only the pom file to my snapshot repository in Maven?

纵饮孤独 提交于 2019-12-05 02:12:16

Basically to the -Dfile parameter, instead of the artifact, pass the pom.xml, but just doing this is not enough. You'll also need to supply the parameters -DgroupId and -DartifactId of the project. Run the command and yay! mvn deploy won't give you any issues now. Here's a sample deploy command :

$ mvn deploy:deploy-file -DpomFile=pom.xml -Dfile=./pom.xml -DgroupId=my.group.id -DartifactId=artifact-id -DrepositoryId=bigdata-upload-snapshots -Durl=http://maven.mymaven.com/content/repositories/snapshots/

A prerequisite for this is that the repository be added in your settings.xml

I never heard of such a possibility and also would be very astonished if that would be possible. As the pom and the resulting artifact are some kind of unit it would make no scence (to me) to deploy only parts of them.

Nevertheless you should consider to make a separate pom project which specified dependencies and plugins you might want to use on your JAR/WAR projects like this:

<groupId>foo.bar</groupId>
<artifactId>my-pom</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>

and then inherit that pom project by your JAR/WAR projects like this:

<parent>
    <groupId>foo.bar</groupId>
    <artifactId>my-pom</artifactId>
    <version>1.0.0</version>
</parent>

This is called project inheritance. You can change and deploy your pom project independent of the "child" artifacts.

EDIT after reading motivation:

As I understand you want to prevent maven to resolve SNAPSHOT artifacts from a repository (so that local version won't be overwritten). Have you ever tried to use the mvn -nsu option (see mvn -help)?

-nsu,--no-snapshot-updates             Suppress SNAPSHOT updates

I never tried it but found this reported issue. Nevertheless I would give it a try (as the issue is not commented yet).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!