mvn clean install command

Hello World!
I am seeking to understand the efficiency(usage) of the command above when working with openMRS modules.

  • After making changes in my code base, when is the mvn clean install effective to a commit? Before running git add -i or after adding the changes
  • Does running again mvn clean install on a module after making changes overrides the previous dependencies located in .m2 directory in case this command was once triggered on the same module. Or I manually need to first delete these dependencies from the respective directory for the new dependencies to take effect
  • How does maven [.m2 directory] handle multiple local branches when mvn clean install is triggered on different branches of the same module.
    cc: @mksd @ibacher @dkayiwa
1 Like

Hello @kdaud as long as i know mvn clean install contains two commands bundled into one.

  1. mvn clean:
    This cleans/deletes all of the downloaded dependence resources as specified in the project’s pom file from the .m2 folder.

  2. mvn install:
    This downloads maven dependencies into the .m2 folder from the internet or from other folders inside the .m2 folder as specified in the pom file.

Hence, there is no need to delete the contents if u run mvn clean install because maven has already done that for you.

3 Likes

As far as I know mvn clean does not touch .m2. It only cleans the build’s files:

The Maven Clean Plugin, as the name implies, attempts to clean the files and directories generated by Maven during its build. While there are plugins that generate additional files, the Clean Plugin assumes that these files are generated inside the target directory.

Ref.: Apache Maven Clean Plugin – Usage

3 Likes

Ideally mvn clean install has not helped out. Going through a manual process to first delete the respective old folder where these dependencies were stored within .m2 directory then build again resolved the concern. However, this looks tiresome doing it manually; is there a way i can do this at build time some thing like a flag added on the command. cc @mksd

When i run mvn clean install, the cmd console displays

downloading from < url… >

Yet when i run mvn install the downloading section is skipped, it just displays the number of files compiled and runs tests.

@mksd May you please help me understand more why maven does the above?

As @mksd highlighted, clean install leans your target folder and recompiles. If you are handling any faulty artefacts, you need to manually handle those as you have done

1 Like

@jnsereko whether Maven attempts to download again dependencies or not depends on a lot of things, including settings that may be picked up from .m2/settings.xml.

It makes sense that a clean install will have to do more things than a mere install, including attempting to download stuff that otherwise may already be lingering in the build folders (in /target typically.) But this is speculative since I don’t know what you’re doing exactly.

The only thing I can say for sure from the top of my head is that you can force Maven to always fetch dependencies by using -U:

mvn -U clean install
1 Like

thank you @mksd and @k.joseph for broadening my understanding of maven

hello @kdaud , it seems to me that youre mixing two things together. the git work flow and the maven work flow .

Git is a version control System and its main purpose is to track the changes you make to files, so you have a record of what has been done .

Maven is an automation and management tool .It helps to build Projects, dependency and documentation. It simplifies the build process.

The only case when the two workflows would overlap , is when maven is used to makes some changes in your source files like applying formatting , adding LIcenece headers etc .Thats when you would probably run a mvn clean install before git add , other wise the work flows are independent of each other

1 Like

Thanks @mozzy for this clarification.