Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven deploy: forcing the deploy even if artifact already exists

Tags:

I'm building a project, which is made up from several (sometimes unrelated) modules and some more non standard java modules (built with ANT).

Each maven module is deployed to the releases repository on completion.

If the build fails in the middle, I might have some modules already deployed, so if I try to rebuild, the new attempt to deploy will fail since the artifacts are already deployed.

Is it possible to force a deploy or instead, remove the deployed artifact before I deploy again?

like image 872
Eldad Assis Avatar asked Jun 24 '12 05:06

Eldad Assis


People also ask

How can I prevent previously deployed artifacts from being overwritten?

The reasoning for this is to make sure that valid releases don't accidentally get overwritten. If an artifact really does need to be re-deployed, one of our developers can use the Artifactory web interface to delete it. Then they can deploy the new copy. Thanks!

What is difference between mvn install and deploy?

mvn:install copies your packaged Maven module to your local repository (by default, in ~/. m2/repository ), to be accessed by other local Maven builds. mvn:deploy uploads your packaged Maven module to another (usually remote) repository, to be accessed by other, not necessarily local, Maven builds.

Does mvn deploy also build?

So, the answer is yes, mvn deploy will execute install and build the project artifacts.

How does maven deploy work?

The deploy plugin is primarily used during the deploy phase, to add your artifact(s) to a remote repository for sharing with other developers and projects. This is usually done in an integration or release environment.


2 Answers

It sounds like the middleware admins have configured your remote repo instance (Nexus or Artifactory or whatever) to not allow artifact redeployment, and as @khmarbaise says there are good reasons for that. Nexus can be configured to allow artifact deletion by users in a particular role or with artifact deletion privileges. If your admins have it set up that way perhaps you can request the delete privilege and remove the offending artifacts. Or, perhaps the Nexus admin will agree to do it for you.

If neither of these is possible, here are some things to try which might keep this from happening in the future:

  1. If you are using the release plugin, do a dry run (-DdryRun=true on the release:prepare command line) first. Maven should report any errors without committing to SCM.
  2. Try running mvn install on your group of projects first. This will install the artifacts to your local repo, not the remote. If there's a problem you can whack the artifacts out of your local repo and start from scratch, repeating until you get a complete build.
  3. If you are running a multi-module build, there are command line options that allow resuming a Maven build from a particular project forward.
  4. Define -Dmaven.deploy.skip=true on the Maven command line. This is similar to suggestion #2, except Maven will actually load & configure the deploy plugin, it just won't do the actual deploy to the remote repo. Once everything works, remove the skip property.
like image 109
user944849 Avatar answered Sep 27 '22 22:09

user944849


I know it might be late, but in Nexus there's an option where allows the redeployment of artifacts.

enter image description here

Just select the repositories in the left, choose the repository you want to change the policy and then set it to Allow Redeploy.

like image 31
leozin Avatar answered Sep 27 '22 23:09

leozin