Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What files in a Maven project should be committed to git?

Tags:

I want to know what files in a Maven project should be committed to git.

Am I suppose to perform a mvn clean before committing, or do I add certain files to the .gitignore file?

like image 409
tyleax Avatar asked Aug 10 '18 19:08

tyleax


People also ask

Does Maven use Git?

GIT holds the sourcecode of your application. MAVEN is used for dependency management. It holds the binary dependecies of your application. It also creates a abstraction of the used IDE.

What should I write in Gitignore?

gitignore should list the names or name-patterns of files that will be found in work-trees when working with your project, but that should not be committed to the project. In other words, it's not OS-specific, it's project-specific.

What is the difference between Git and Maven?

GitHub can be classified as a tool in the "Code Collaboration & Version Control" category, while Apache Maven is grouped under "Java Build Tools". Some of the features offered by GitHub are: Command Instructions. Source Browser.


2 Answers

Personally I use Maven gitignore and Java gitignore for a Maven project. You might need to adjust it with the languages used in your Maven project.

https://github.com/github/gitignore/blob/master/Maven.gitignore

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

https://github.com/github/gitignore/blob/master/Java.gitignore

# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

Is it good practice to perform mvn clean before committing, or do I add certain files to the .gitignore file?

Add rules to your .gitignore file first, which makes Git ignores the undesired files correctly. Understanding Maven standard directory layout will also help you better determine which are the undesired directories.

like image 86
Mincong Huang Avatar answered Oct 03 '22 20:10

Mincong Huang


Check this:

https://www.gitignore.io/api/maven

In general you should ignore all targets and metadata. If you ignore targets, mvn clean is not required before pushing.

like image 36
mc20 Avatar answered Oct 03 '22 20:10

mc20