I'm creating a new Spring Boot app. I'm more than moderately familiar with .gitignore
patterns, but I see something deliberately templated that has the smell of "intent" on it. The below is produced by the Spring Initializr in many IDEs.
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
...
...
build/
!**/src/main/**/build/
!**/src/test/**/build/
I believe this has something to do with maven's multi-module project feature, but Initializr apps are not multi-module (at start). That aside, what I'm reading here? If I took a stab at what I think is being stated it is something I do not want to do (as a general practice).
"Ignore
target/
folders wherever encountered, buttarget
folders below the top-level insome/path
/src/main/
deeper/still
/target/
include those."Oh, do the same for NetBeans
build/
directories!"
This doesn't quite make sense. Why would I ever commit target content generated by the build? Thus I'm trying to deduce the intent of the Spring engineers.
Update
In fact, that's exactly what this does, includes target
or build
directories deeper in the root. To what end?
mkdir -p some/path/src/main/deeper/still/target/
touch !$/test.txt
This new target
directory is included for staging and commits. Remove this and it's ignored.
Basically, these "includes" (negated excludes) make sure directories beneath src/main
and src/test
that may be named target
, for example, a package name, are not missed in a commit.
Per a discussion on the Spring Initializr gitter, Andy Wilkinson, a Spring committer, noted:
It's to prevent the ignore for Maven's build output directory (
target
) from causing code in a package namedtarget
from being ignored.
In many cases, safely deleted in individual use cases, "unless you work for Target" (Target Brands, Inc. might have packages namespaced as com.target.api.*
) (h/t to Andy for the example).
My question should have been answered in the use of src/main
and src/test
, but I let the misdirection of the word, target
, confuse me. In fact, I was demonstrating this in my own example, but couldn't get past the word. D'oh!