Home > Software design >  How to suppress deleting "target" dir on "mvn clean"
How to suppress deleting "target" dir on "mvn clean"

Time:07-01

Is it possible to suppress deleting default target directory during mvn clean? Current process deletes entire directory with all its content while I need to keep empty dir on delete.

I guess I will be able to set such configiration by using <artifactId>maven-clean-plugin</artifactId>, but still there remains the implicit process of the mvn clean which deletes entire directory anyway.

CodePudding user response:

I assume you can make use of excludeDefaultDirectories: set it to true and manually list the subdirectories you want to purge via filesets. I haven't tested this but it should work. Let me know how it goes.

CodePudding user response:

A symbolic link on Linux (as for other Unix-variants) uses its name, not the actual directory to resolve where it points. You can then use ls -P on BSD-variants like MacOS or ls -L on GNU variants (untested) to see what is pointed to.

The information stored in a symbolic link does not get invalidated when target is deleted, so when the directory is created again the symbolic link will work again.

On my Mac:

ravn@freewifi demo % mkdir target; ln -s target t
ravn@freewifi demo % ls -lP t
lrwxr-xr-x  1 ravn  staff  6 30 Jun 18:40 t -> target
ravn@freewifi demo % ls -l t/
total 0
ravn@freewifi demo % rmdir target; ls -l t/
ls: t/: No such file or directory
ravn@freewifi demo % mkdir target; ls -l t/
total 0
ravn@freewifi demo % 

The trailing slash is to ensure that the symbolic link is followed (or at least tried to).

  • Related