0

When I build my Spring Boot application using ./mvnw install, it creates a folder named "target" that contains the output of the build.

I would prefer for that folder to be hidden on Linux (for example using the name ".target").

Is there a way to specify an alternate name for the Maven "target" folder?

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
  • 1
    Why ? What is the advantage? Stay with the convention it's easier. Why should that folder being hidden? It's folder has been created and it should be visible..it should be on the ignore list for version control (for example `.gitignore` or with `svn:ignore` property ).. – khmarbaise Apr 11 '20 at 12:20
  • @khmarbaise, The `.git` folder is hidden. `.gitignore` is hidden. `.gitignore` lists several settings files/folders which are hidden. What makes `target` so special that it gets to clutter my project tree when I want to see only the files that I've created. `.gitignore` doesn't help with this if I'm running `ls` or `tree`. – Brent Bradburn Apr 11 '20 at 14:43
  • ...Changing bad conventions is progress. – Brent Bradburn Apr 11 '20 at 14:46
  • The Node package manager (npm) has the same flaw: [Can a custom directory name be used instead of 'node_modules' when installing node packages?](https://stackoverflow.com/q/21818701/86967) – Brent Bradburn Apr 11 '20 at 15:30
  • 1
    The .git folder is something differerent. – khmarbaise Apr 11 '20 at 15:33
  • @nobar You are not changing conventions, you are breaking them. It does not matter if this your private project, but you confuse other programmers who are used to Maven that will try to build your project. – J Fabian Meier Apr 11 '20 at 19:18
  • Maven violated Linux convention by using a non-hidden name for a tool-managed folder. In this case, it isn't confusing -- merely distracting. And it gets in the way of certain workflows (such as examining your project structure with [`tree`](https://linux.die.net/man/1/tree)). – Brent Bradburn Apr 11 '20 at 19:35
  • 1
    Which Linux convention? The target directory is a directory which contains relevant information for the user which means the built artifacts etc. so it does not make sense to put them into a hidden directory which exactly is the difference between the `.git` directory which is only managed and never being touched by user directly whereas the `target` could and needed.... – khmarbaise Apr 12 '20 at 11:57
  • Maven is cool, though -- as I discovered by asking this question, the name and location of the target directory is configurable. Sure, you may need to also configure other tools that access target-internal data (such as copying the .jar for deployment). That shouldn't be a problem, since this configurability is already needed to handle path differences between [Maven](https://stackoverflow.com/a/51090252/86967) and [Gradle](https://stackoverflow.com/a/49200169/86967). – Brent Bradburn Apr 12 '20 at 19:23
  • The way `.git` is managed vs Maven's `.target` :) is very similar for many workflows. With Maven (from the command-line), I can compile, test, run, install (to the hidden folder `~/.m2`), etc. without ever looking inside the `.target` directory. There are special, but rare, cases where I might need to explore the contents of both -- hidden folders are still easily accessible for that, but they have the feature that they don't ["clutter"](https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory) the listing of files that are created and managed by humans. – Brent Bradburn Apr 12 '20 at 19:43

1 Answers1

1

The target folder is very important, ¿why you want to rename it? If isn't really necessary, in think that you shouldn't rename it.

I found 2 related posts (this and this). If it helpt to you, only add to your pom:

<build>
<directory>/yourDirectory/.target</directory>
</build>

You can put it into a profile too. Hope it has been helpful.

UrbanoJVR
  • 1,010
  • 1
  • 7
  • 11
  • "the intent is simply to not "clutter" the display of the contents of a directory listing with files the user did not directly create." -- [Hidden file and hidden directory](https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory) – Brent Bradburn Apr 11 '20 at 03:38
  • 2
    @nobar Nevertheless, renaming standard Maven folders is usually considered bad practise. – J Fabian Meier Apr 11 '20 at 07:17