Android Studio using Git: gradle-wrapper.jar in version control - java

Android Studio recommends using the gradle wrapper in the build work flow. However, if you are using git for version control, .jar files are ignored and are said not to be checked in, which I get. But my workflow is a little different than the average person. We are also using Team Foundation Server and git both. The gradle build gets called using a custom MSBuildTask. Here is what my .gitignore file looks like:
# Built application files
*.apk
*.ap_
# Files for the Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
The way it currently works is first we pull both from TFS and our git repo into a common location, then we merge the two, check the result back into TFS and push the result back to the git repo. After this is complete, the custom MSBuildTask is executed which basically just calls "gradlew build". However, this fails because the gradle-wrapper.jar file isn't being pushed to git, its being ignored. Any ideas on how to accomplish this? Thanks in advanced!

As Peter mentioned, jars are not ignored due to your .gitignore file; I guess the jars are ignored due to a .gitignore file located in a parent directory of your project directory. Can that be the case ?
Anyhow, if that is the case, you can try using a negation in your .gitignore file, something like:
!**/*.jar
In that way, you override rules from a .gitignore file in one of the parent dirs.

Related

How to add back missing gradle-wrapper.jar to Git repo for Jenkins to do its job

Whenever my Jenkins job clones my project from GitHub, it is not able to run gradlew command due to missing gradle-wrapper.jar under myproject/gradle/wrapper folder. I have to manually copy paste from another source and re-run the Jenkins job.
Somehow I erroneously had deleted this jar file. The .gitignore file does not detect the newly added jar file either. Due to which I am not able to commit the missing jar to repo. Any suggestion on how to solve this issue.
I am very specific about using gradlew and not gradle
Below is the .gitignore file
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/
### Gradle ###
.gradle
build/
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache
### Gradle Patch ###
**/build/
### Java ###
# Compiled class file
*.class
# Log file
*.log
# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar
Solved this by commenting the *.jar in gitignore file and added the specific gradle-wrapper.jar to repo

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

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?
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.
Is it good practice to perform mvn clean before committing, or do I
add certain files to the .gitignore file?
Executingmvn clean before committing is not practical at all. Developers can forget that and besides they should rebuild their projects at each commit.
The correct way is using .gitignore to specify files to ignored in the tracking. Just commit it and push into the remote branch and all developers could work with the same rules.
I want to know what files in a Maven project should be committed to
git.
You want to commit/push files that you want to version/track.
But it is very broad. You cannot have rules just for Maven. Maven have some specificities (target folder for example that you want to ignore) but you would have probably more things to ignore.
You want to generally commit/push the source code and application configuration files such as pom.xml or any configuration files used in your build but you can also add any other kind of files. For example committing a changelog or even a word document (more rare but possible) may also be valid.
Generally what you don't want to commit are files that :
depends on the developer machine (IDE, custom files)
created by a build operation (target folder in Maven but you could also have other folders according to your pom configuration)
temporary files using during the build, the application execution or still the release operations.
archives
Check this:
https://www.gitignore.io/api/maven
# Created by https://www.toptal.com/developers/gitignore/api/maven
# Edit at https://www.toptal.com/developers/gitignore?templates=maven
### Maven ###
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
# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
# End of https://www.toptal.com/developers/gitignore/api/maven
In general you should ignore all targets and metadata. If you ignore targets, mvn clean is not required before pushing.
I had a Maven project in VSCodium and had to decide whether to commit the .project file or not. That should be linked to in this Q/A since it happens with other IDE:s as well that have Maven extensions.
This is 2010, only for Eclipse:
.classpath and .project - check into version control or not?
which says overall that it should be committed. I guess the discussion is timeless. It is a Maven generated file, but it should still be in the repository, and even more, if the repository is at work with the same setup and tools by the team.
Other questions:
Should I keep my project files under version control? [closed]
Java project: should .classpath .project file be committed into repository? [duplicate]
The same for the .classpath. Even if it is made by Maven, it should be in the repo.
I am a beginner at Maven and only guess this. I cannot understand why this was not in this Q/A up to now. The accepted answer lists the ignored files, but from reading that, I was not fully sure what to do with these meta files from Maven. And there is even one answer that lists the two files as files that are to be ignored in this Q/A here. Which, as far as I can see from a repository I took over, and guessing from the accepted answer, is wrong: the two files belong to the version control.

Module files needed to run an application in gradle

I have an application in gradle divided into several modules https://zapodaj.net/745369ca57478.png.html. I want to throw him onto GitHub now. I'm not sure which files are needed. I currently have added in the gitignore file
# gradle config
.gradle/
# Intellij Idea project files
.idea/
out/
*.iml
# project binaries
build/`
In each .gitigore file I have typed the same thing. But in modules, I do not need files, perhaps
gradlew
gradlew.bat
Can I remove these two files from the modules and only stay out of the modules only? It seems to me that these two files are only needed outside the modules.
Yes, if you already include all the module in setting.gradle, then you don't need those 2 file and the gradle folder in each module
include ":core", ":common", ":web"

adding android project to git

Which are the files that I have to ignore when adding a project to git?
Should I add the .classpath file?
What is the purpose of .classpath?
Im using eclipse and pushing to a Jenkins server
Typical gitignore file for android would include this:
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
From Gitignore on github
While creating a project in Eclipse, by default it creates a .classpath file in the project directory. That file will be used for storing file names and other dependent files needed in the classpath to compile and execute the project successfully. Normally this file will be updated automatically when ever you update the project libraries etc.
You should add it to git in my opinion. See this thread for more:
.classpath and .project - check into version control or not?

Typical .gitignore file for an Android app

Just put an Android project under git (beanstalk) version control via the command line (mac terminal). Next step is to set up exclusions.
To those of you who have already been down this path:
What should a typical .gitignore file look like for an android project?
Project set up in Eclipse
You can mix Android.gitignore:
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
with Eclipse.gitignore:
*.pydevproject
.project
.metadata
bin/**
tmp/**
tmp/**/*
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
In addition to what the others have suggested, I'd like to add the proguard folder, in case you are using it. You can either ignore the whole folder or just dump.txt, seeds.txt and usage.txt. Basically, it's a good idea to keep mapping.txt versioned, so that you can debug obfuscated stack traces from your users. More details here.
This is my standard Android .gitignore and .hgignore file. It usually works pretty well.
bin
gen
target
.settings
.classpath
.project
*.keystore
*.swp
*.orig
*.log
*.properties
seed.txt
map.txt
It has eclipse, vim .swp files, mavens target folder and files for proguard mapping included.
Update: I have put my .gitignore for Android development online.
Well I know that the github/gitignore repository on GitHub has an android .gitignore file. This might be what you want as it should be very general for android development.
The actual content of the mentioned file:
# built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
Here is the one I use in my Android projects, it supports both ADT and Android Studio, so it is good if you are working with a team.
# General Folders
# gradle/ comment this when using gradle wrapper.
build/
bin/
gen/
tmp/
# proguard/ comment if not using proguard.
.gradle/
.settings/
.idea/
# General Files
.project
.classpath
.DS_Store
local.properties
*.iml
# gradlew comment when using gradle wrapper
# gradlew.bat comment when using gradle wrapper
Thumbs.db
# files specific to current project
your_apk.apk
Simply github can generate .gitignore for Android projects repositories
And its content will be like the following
# Built application files
*.apk
*.ap_
# Files for the ART/Dalvik VM
*.dex
# Java class files
*.class
# Generated files
bin/
gen/
out/
# Gradle files
.gradle/
build/
# Local configuration file (sdk path, etc)
local.properties
# Proguard folder generated by Eclipse
proguard/
# Log Files
*.log
# Android Studio Navigation editor temp files
.navigation/
# Android Studio captures folder
captures/
# IntelliJ
*.iml
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
.idea/caches
# Keystore files
# Uncomment the following line if you do not want to check your keystore files in.
#*.jks
# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild
# Google Services (e.g. APIs or Firebase)
google-services.json
# Freeline
freeline.py
freeline/
freeline_project_description.json
# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md
In Addition, if you use IDEA's IntelliJ, and you build Artifacts (and you should), then you might want to add:
out/
(that's where Artifacts are built by default).
And if you don't want to share your IntelliJ project stuff ignore
.idea/
In my project root I have a file .gitignore. It contains:
/bin/
/gen/

Categories