IntelliJ, Gradle und Git: gitignore

temi

Top Contributor
Hallo zusammen!

Nach dem Erstellen eine neuen Projektes in IntelliJ mit Gradle erhält man ja ungefähr folgende Struktur:
Code:
>.gradle
>.idea
>gradle
>src
build.gradle
gradlew
gradlew.bat
settings.gradle

Innerhalb von .idea findet man auch eine minimale .gitignore, die ich zunächst mal direkt in die oberste Verzeichnisebene verschoben habe.

Auf der IntelliJ-Webseite findet man einen Vorschlag für den Inhalt von .gitignore:
Code:
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn.  Uncomment if using
# auto-import.
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

Teile davon brauche ich sicher nicht, aber sie schaden wohl auch nicht.

Fehlt da noch was? Was ist mit den Ordnern .gradle und gradle?
 
K

kneitzel

Gast
Also erst einmal: Du musst die .gitignore nicht verschieben. Du kannst die auch in Unterverzeichnissen nutzen um da weitere Regeln zu haben.

Ich selbst würde nie so rigoros alles ausschließen wie von @JennyL empfohlen. Die Gefahr ist in meinen Augen einfach zu groß, dass dann plötzlich Dateien nicht eingecheckt werden. Diese Gefahr eines Datenverlustes ist in meinen Augen zu groß.

Die .gitignore bei Java Projekten könnte ansonsten solche Standard-Einträge haben (Das ist einmal mit einem Gradle Projekt erzeugt worden):
Code:
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

Aber ich selbst habe sowas in der Regel nicht wirklich so massiv drin. Was man erkennen kann: Hier wird generell kein Projekt mit eingecheckt. Das Projekt selbst ist gradle. Du kannst es mit der IDE öffnen, die Du nutzen willst, aber die Dateien kommen dann nicht mit rein nach git.

Meine Arbeitsweise ist das nicht. Ich mag es, dass die Projekte auch mit eingecheckt sind. Alleine um im Team ein gemeinsames Projekt zu haben (so alle die gleiche IDE nutzen). Das ist schon ein Vorteil, gerade wenn auch mal weniger versierte Leute da rein schauen müssen. (Junior Member, C++ Entwickler, die dann auch mal im Java Part rein schauen wollen, ...)

Da ist aber schlicht die Frage: Was ist deine Erwartungshaltung? Was genau hat Priorität?
 

temi

Top Contributor
Was ist deine Erwartungshaltung? Was genau hat Priorität?
Ich möchte nicht unnötig viel einchecken, würde also wenigstens build/ und out/ ausschließen. Sowie ggf. Daten, die z.B. durch build.gradle erzeugt werden und sich sozusagen selbst rekonstruieren können, wenn du verstehst, was ich meine.

Allerdings muss ich zugeben, das ich nicht so sicher bin, was dazu alles notwendig ist.

Ich mag es, dass die Projekte auch mit eingecheckt sind.
Das bedeutet, dass du alles außer die beiden o.g. eincheckst, um das komplette Projekt zur Verfügung zu haben?

Oder schließt du noch die userspezifischen IDE-Sachen aus?
Code:
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

build/
out/
 
K

kneitzel

Gast
Die User-spezifischen Dinge sollte IntelliJ bereits ausschließen, denn dazu wurde in .idea ja ein .gitignore erzeugt.

So dieses da ist, musst Du also nichts mehr selbst machen, aber die generierte Datei sieht bei mir so aus:
Code:
# Default ignored files
/shelf/
/workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# Editor-based HTTP Client requests
/httpRequests/
 

temi

Top Contributor
Die User-spezifischen Dinge sollte IntelliJ bereits ausschließen, denn dazu wurde in .idea ja ein .gitignore erzeugt.
So dieses da ist, musst Du also nichts mehr selbst machen, aber die generierte Datei sieht bei mir so aus:
Das ist vorhanden, aber etwas kürzer:
Code:
# Default ignored files
/shelf/
/workspace.xml
Zusätzlich würde ich noch ein .gitignore ins Projektverzeichnis legen:
Code:
# Gradle and Maven with auto-import
.idea/artifacts
.idea/compiler.xml
.idea/jarRepositories.xml
.idea/modules.xml
.idea/*.iml
.idea/modules
*.iml
*.ipr

# IntelliJ
out/
build/
Ist das einigermaßen plausibel?
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
MiMa IntelliJ GIT Local Zweig?? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
D Intellij source controll zeigt nicht alle klassen an ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
MiMa Die Sourcecode Verzeichnisse verschwinden in IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
M Eclipse oder IntelliJ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
krgewb IntelliJ durchsucht .log-Dateien IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
Oneixee5 IntelliJ JavaEE IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
krgewb GUI-Elemente in IntelliJ verschwunden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
MiMa IntelliJ Projekt umbenennen?? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
MiMa IntelliJ dubious ownership in reposity? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
JAnruVA IDEA IntelliJ JavaScript in IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
D Crawler funktioniert in intellij aber in Eclipse nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
W Speicherbelegung in IntelliJ auswerten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
N generate selected getters with intellij IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
MiMa Netbeans zu IntelliJ mit Maven konvertieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
temi IDEA IntelliJ Intellij new UI IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
D strg + alt + B funktioniert nicht [IntelliJ] IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
MiMa IntelliJ Maven Projekt erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 15
MiMa IntelliJ GIT-Verzeigung zu Master hinzufügen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
MiMa Nebtbeans Projekte nach IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
L source folder und code highlighting IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 21
D lesen von json Dateien in Intellij IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 13
MiMa Doppelten Code in IntelliJ finden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
H Branches vergleichen - GIT, IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
frager2345 Datenbankzugriff Intellij IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
Y IDEA IntelliJ Warum findet IntelliJ die maven property nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
J IntelliJ IDEA IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
krgewb IntelliJ Idea - Alles eingeklappt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
LimDul IDEA IntelliJ Tipps für den Umstieg von Eclipse auf intelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
F IntelliJ IDEA Community Edition IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 26
S IDEA IntelliJ GUI Component Tree anzeigen in IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
D Intellij Memory Settings IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
krgewb In IntelliJ alles eingeklappt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
N IDEA IntelliJ Intellij lässt keine neuen archetypes erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
S IDEA IntelliJ Scenebuilder in Intellij Idea am MAC OS X IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
OnDemand IntelliJ Branching Master/DEV Berechtigungen möglich? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
9 IDEA IntelliJ Wie kann man ein JUnit Test bei IntelliJ durchführen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 11
9 IDEA IntelliJ IntelliJ lässt nicht ein Code ausführen, wenn irgendwo in andere Klasse Fehler ist. IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
krgewb IntelliJ - Zu application.properties springen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
O IntelliJ IDEA Lizenz IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 15
D Intellij mehrere Programme in einem Projekt bearbeiten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
M Intellij build jar funktioniert nicht ! IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
Z Intellij zeight H2-Datenbank nicht an IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 9
P Maven für Intellij IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
P Intellij "httpRequest" ins Projekt mit einbinden? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 49
N Frage zu meinen IntelliJ-Einstellungen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
mrBrown IntelliJ 2020.1 - Maven Projekte nicht ausführbar IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
W IntelliJ soll nicht immer alle Code-Files checken IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
Thallius Falsches Warning in IntelliJ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
D JavaFX 12 / SDK 12 -> IntelliJ error IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
R IDEA IntelliJ Intellij klaut mir zu viel zu viel Speicherplatz weg! IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 22
M Intellij IDEA lädt Font nicht und Darcula funktioniert nicht IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
M Intellij IDEA Programm ohne Main-Methode starten IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
Y Intellij mit Android SDK IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
B IntelliJ - .properties in jar einbinden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 7
E Maven-Installation für Intellij IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
U IDEA IntelliJ IntelliJ IDEA automatische Formatierung deaktivieren IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
K IntelliJ unter Linux: Probleme beim Ausführen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
M Idea IntelliJ - Starten der Mainmethode ? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
A IDEA IntelliJ IntelliJ Maven oder Webprojekt, kann keine normalen Java Klassen erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
K IDEA IntelliJ Umstieg von ADT (Eclipse) auf Android-Studio (IntelliJ IDEA) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
R intellij idea mit SVN tortoise 1.8 verwenden IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
X "Extract Method Object" aus IntelliJ auch in Eclipse? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
U [IntelliJ] Variablen Refactoring IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
H Intellij 8.1.3 JDSK Probleme IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
S Metriktools für IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
M Grails Plugin in IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 6
A IntelliJ zeigt meine class-Files nicht an!? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
L Intellij IDEA 8 - Wie ist eure Meinung? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 38
J IDEA IntelliJ IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 10
G IDEA IntelliJ Problem IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
8u3631984 VS Code und Gradle Sub Module IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 3
N Eclipse debug Gradle-Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
J Kombinationsproblem: netbeans, gradle, mysql, json IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
temi Gradle: Externe Abhängigkeiten einschließen? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
J Bekomme keine lauffähige jar (netbeans/gradle) IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 12
J Install JasperReports on netbeans/gradle Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
J NetBeans gradle Projekt, unter neu keine Auswahl JavaFX IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
J Gradle add Bom Properties IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
J Gradle localPublish POM IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 11
J mavenBOM alternative für Gradle IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
B IDEA IntelliJ Import Gradle: Plötzlich Android Projekt IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 14
M gradle import in eclipse schlägt fehl IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
J Maven in Gradle builden? IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 11
N Gradle Ober und Unterordner zusammengefasst IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 4
L IDEA IntelliJ Gradle sync failed IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 2
T NetBeans "Gradle Project" in "Web Application" nutzen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 5
D Jenkins/Gradle maven-publish Problem IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
temi IDEA IntelliJ Gradle und JavaFX IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 15
B IDEA IntelliJ Gradle Projekt debuggen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
temi IDEA IntelliJ Gradle - Erste Schritte IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 8
M Eclipse lauffähiges Jar auch mit gradle erstellen IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0
D Gradle - DSL und Repositories von Maven IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 1
N Path must include project and resource name: /.gitignore IDEs - Eclipse, IntelliJ IDEA, BlueJ & mehr 0

Ähnliche Java Themen

Neue Themen


Oben