gradle wrapper not overriding default wrapper properties - gradle

We are using gradle wrapper for our project
There is a gradle-wrapper.properties generated as part of the wrapper
We would like to know whether the gradle-wrapper.properties in the wrapper will over ride the gradle.properties available in the user home directory.
For eg: if Developer has a different gradle installation and has a gradle.properties in his machine, and when we enforce gradle wrapper, we observed that the local gradle.properties is considered for build.
Is this the expected behavior?

No, the gradle properties file specifies the properties to be used by gradlew script, like what version to download and use, and not properties for the build process.
Moreover, the gradle.properties file should be shipped along with your source code.

Related

IntelliJ Idea - How to enable gradle wrapper

Importing gradle project into intelliJ IDEA : use default gradle wrapper option (not configured for the current project) is disabled.
How to solve this?
So you ask why this option is grayed out?
That because the your project doesn`t have a wrapper.
You can add a wrapper by using the task
gradle wrapper
This will add a gradle directory , a file named gradlew.bat and one named gradlew
after this you can reimport your project or
change it in your settings control + shift + s

gradle.properties file is missing from .gradle folder in windows

I have installed gradle with chocolatey package manager, but in .gradle directory there is no gradle.properties file. Do I need to re-install gradle? or what should I write besides what I need to add in grdle.properties file If I will create it?
P.S: I use gradle plugin in Spring Tool Suite, and I need to add something in the gradle.properties file concerning the project
The propery file gradle.properties is not created automatically during Gradle installation. You can create this file manually and add your specific configuration into it. Note that there are two places where you can create a gradle.properties file, as described in documentation Gradle configuration properties

Is it necessary to install Groovy for Gradle

I'm new to Gradle. I see that Gradle lib already has a file 'groovy-all-2.4.12.jar' in lib folder and I don't seem to have any issues with tasks and or dependencies. Still, is it necessary in any scenario to install Groovy on my system on top of it?
Reason why I ask is that, when I do 'gradle -v' in command prompt, I see few warnings. Please see attached screenshot.
With gradle it is strongly recommended to use the Gradle wrapper committed into the project you are building instead of a system-wide gradle distribution (that is gradlew and not gralde). This guarantees the matching version of Gradle your project has been tested with.
With the Gradle wrapper you do not need to care about any dependencies that Grade itself needs, such as groovy and you really do not need to install anything of Gradle at all as the wrapper in your project will download all it needs on the first run.
The minimum setup for the Gradle wrapper is:
/gradlew - unix shell script
/gradlew.bat - windows batch script
/gradle/wrapper/gradle-wrapper.properties -- the properties file defining the version
/gradle/wrapper/gradle-wrapper.jar -- the minimal jar (50Kb) that takes care about the rest
The above files must be committed into your project and this is what 99% of all gradle projects do. You will find further details here https://docs.gradle.org/current/userguide/gradle_wrapper.html

Specify project version

I have found 3 ways to define my project version.
In the documentation http://www.gradle.org/docs/current/userguide/dependency_management.html they talk to specify it in the manifest or the foldername (which already contains the project name).
Coming from a maven project I'm used to defining my version in my pom.xml and I have found project that also define their version in the gradle.build file in the version property
I'm looking for the correct way to handle my project version, so I can also depend on a certain version of my project.
The link that you have shared talks more about dependency management, and about good practises for versioning your artifacts.
There is a one-to-one relationship between a Project and a build.gradle file.
Also your build.gradle gives you a property:
version - The version of this project. Gradle always uses the toString() value of the version. The version defaults to unspecified.
This fits in for the project version.
You can set it directly in build.gradle, but depending on your use case you could pass it externally - using gradle.properties for example in multi-project builds.
You can also directly add properties to your project objects using properties files. You can place a gradle.properties file in the Gradle user home directory (defaults to USER_HOME/.gradle) or in your project directory. For multi-project builds you can place gradle.properties files in any subproject directory. The properties of the gradle.properties can be accessed via the project object. The properties file in the user's home directory has precedence over property files in the project directories.
Check for more details: http://www.gradle.org/docs/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:configurations%28groovy.lang.Closure%29
Add a gradle.properties file in the root directory of your project (same level as build.gradle) with this content:
version=0.0.1-SNAPSHOT

Building spring with gradle

I am learning to use git and gradle to build Spring 3.2 on my local system.
I cloned the git repo and used the gradlew command to start the build like so:
gradlew build
I also have the GRADLE_HOME set up and added GRADLE_HOME/bin to my PATH variable.
Every time I start up the build I see a .gradle directory being created in my directory C:\Users\Ayusman and it seems to download gradle binaries.
My questions:
Since I already have gradle installed on my system; why does it have to download gradle?
Can I force gradle to put my dependencies in a specific directory instead of the users folder (like I can specify in maven)?
Can gradle be pointed to pull from a local repo instead of internet?
ad 1. In order to build with your locally installed Gradle, you have to invoke gradle rather than gradlew. The purpose of gradlew (called the Gradle Wrapper) is for everybody to use the same Gradle version and not having to install Gradle manually.
ad 2. To change where Gradle puts dependencies (and other global information), you can set the GRADLE_USER_HOME environment variable.
ad 3. You just need to add another repository declaration to build.gradle. Something like:
allprojects {
repositories {
maven {
url "http://..."
}
}
}
If you want to use this repository for all your builds, you can put the same declaration into ~/.gradle/init.gradle.
Because gradlew invokes the gradle wrapper, which downloads the version of gradle that the build script has been written for, instead of using your version, which might not be compatible. It does that only once, and then reuses the downloaed version. If you want to use your version of gradle, use the gradle command rather than gradlew, but it might not work if you don't have the appropriate version.
AFAIK, this is done by defining the GRADLE_USER_HOME environment variable.
See http://www.gradle.org/docs/current/userguide/userguide_single.html#sec:repositories

Resources