Difference between using gradlew and gradle - gradle

What is the difference between using gradlew and gradle or are they the same?

The difference lies in the fact that ./gradlew indicates you are using a gradle wrapper. The wrapper is generally part of a project and it facilitates installation of gradle. If you were using gradle without the wrapper you would have to manually install it - for example, on a mac brew install gradle and then invoke gradle using the gradle command. In both cases you are using gradle, but the former is more convenient and ensures version consistency across different machines.
Each Wrapper is tied to a specific version of Gradle, so when you
first run one of the commands above for a given Gradle version, it
will download the corresponding Gradle distribution and use it to
execute the build.
Not only does this mean that you don’t have to manually install Gradle
yourself, but you are also sure to use the version of Gradle that the
build is designed for. This makes your historical builds more reliable
Read more here - https://docs.gradle.org/current/userguide/gradle_wrapper.html
Also, Udacity has a neat, high level video explaining the concept of the gradle wrapper - https://www.youtube.com/watch?v=1aA949H-shk

gradle vs gradlew
gradlew is a wrapper(w - character) that uses gradle.
Under the hood gradlew performs three main things:
Download and install the correct gradle version
Parse the arguments
Call a gradle task
Using Gradle Wrapper we can distribute/share a project to everybody to use the same version and Gradle's functionality(compile, build, install...) even if it has not been installed.
To create a wrapper run:
gradle wrapper
This command generate:
gradle-wrapper.properties will contain the information about the Gradle distribution
*./ Is used on Unix to specify the current directory

Related

Gradlew vs gradle wrapper

I have different version for command gradlew --version and gradle wrapper --version, why is that?
Gradlew vs Gradle Wrapper
They are two different executables. gradle is the one installed globally and located in your path. Adding the option wrapper to the gradle command did not change anything for it and you are just seeing the output of gradle --version.
gradlew is the wrapper version installed in the current folder. This version can be different to the gradle one.
A user of my repo did not need to install gradle at all, when I add the wrapper directly to the root folder.
And even if you have a newer version, my project still works with the version I tested it with. So it is quit common the gradlew version is different to your gradle version.
You can update the gradlew version with the wrapper option and you can also use the gradlew wrapper command so the wrapper updates itself.
When you are using linux you can check with which gradle, which gradlew where the exeutables are located (or where gradle for a Windows CMD).
More infos can be found in the offcial documentation:
https://docs.gradle.org/current/userguide/gradle_wrapper.html

Gradle cannot update successfully from v6.5.1 to v7.0.0

I am trying to update my local gradle(out of ide) from 6.5.1 to 7.0.0.
I try two commands from gradle website and network in cmd and path is the root of one of my project(there are gradlew.bat and gradlew files):
gradle wrapper --gradle-version=7.0 --distribution-type=all
gradlew wrapper --gradle-version=7.0 --distribution-type all
And, i try those commands to check the version
gradle -v
gradlew -v
The gradlew updates sucessfully. It prints version 7.0.0.
However, the version of gradle is still in v6.5.1.
How can I update it without download the v7.0.0 packet and cover the files in disk(I am worrying about that i should download all of my packages again in new gradle)?
ps: the gradle is locating in D:\gradle in my disk and java environment is openJDK 15
Thanks agains
I had the same problem and, in my case, the problem was a running gradle demon using the previous version. Check running demons with:
gradle --status
Stop the demons with
gradle --stop
Also I restarted the console/terminal.
You cannot update your gradle standalone version without downloading it, and with gradle wrapper you cannot upgrade your gradle installation, it always works on your current project folder (command gradlew) only. To upgrade a standalone gradle installation (command gradle without the wrapper prefix w), you have to manually download the binaries, include the new bin directory in your PATH environment as described in the manual on the gradle homepage, or use a package manager like sdk man, chocolatey, brew etc.
If you are using the gradle wrapper gradlew for your builds, it works completely independent from your gradle installation.

Some questions about the temporal relationship about gradle and gradlew

I'm learning gradle and some questions bother me
When I want to use gradle, I'd better use gradlew. But when I want to use gradlew, I need a installed gradle. So is that a story about chicken and egg?
Should be gradle-wrapper.jar uploaded to git repository? Some docs say git should track it, but it seems not good to track a binary file with git.
Using ./gradlew you are using a gradle wrapper. The wrapper is part of a project and it is able to download and install a specific version of gradle.
The Gradle Wrapper consists of a few files in your project directory:
gradlew: The shell script Unix users can run to execute Gradle tasks
gradlew.bat The bat script Windows users can run to execute Gradle tasks
gradle/wrapper/gradle-wrapper.jar The wrapper’s executable JAR; this is where the wrapper code resides
gradle/wrapper/gradle-wrapper.properties A properties file for configuring the wrapper
Using the wrapper guarantees that every developer on your team in a specified project is using the same version of Gradle and that they can run Gradle builds.
You should make sure all these are committed to version control
You can easily change the version of gradle used in the project just changing the gradle/wrapper/gradle-wrapper.properties file with the distributionUrl properties. For example:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-all.zip
You can find more info about the wrapper here.
Using ./gradle you need to download and install manually the gradle version before.
It means that every developer in a team can use different version on the same project.

How to update Gradle installation to latest release?

I am trying to initialize a Java application via Gradle Build Init Plugin, with command gradle init --type java-application, but I am getting the following error:
The requested build setup type 'java-application' is not supported.
Supported types: 'basic', 'groovy-library', 'java-library', 'pom', 'scala-library'.
I have the version 3.1 of Gradle (which does not include java-application type).
So, I was wondering how can I update Gradle local installation, without having to remove it, download it and install it again?
You may use Gradle Wrapper, which is the preferred way of starting a Gradle build. Follow these steps to use the right version of Gradle:
Run gradle wrapper --gradle-version 3.3 to install the right version of Wrapper into your project folder.
Henceforward use gradlew instead of gradle. The former uses your Gradle project installation (i.e. version 3.3), whereas the latter uses your computer home directory installation (i.e. version 3.1).
Running gradlew -v returns Gradle 3.3 and gradle -v returns Gradle 3.1 in your case.
Now, run gradlew init --type java-application to setup a command-line application.

how to build Elasticsearch source code using gradle?

I download elasticsearch source code from :https://github.com/elastic/elasticsearch,
I found there is a build.gradlefile,and I have install gradle,
how to build source it?
There is a description fo the way you can build it in the readme file in the repo. According to it:
Building from Source
Elasticsearch uses Gradle for its build system. You’ll need to have
version 2.13 of Gradle installed.
In order to create a distribution, simply run the gradle assemble
command in the cloned directory.
The distribution for each project will be created under the
build/distributions directory in that project.
See the TESTING file for more information about running the
Elasticsearch test suite.
So all you need is to get into the root directory and in command line call gradle assemble, if you have Gradle installed properly, you will find all artifacts under build/distributions directory
gradle assemble seems to yield some errors such as cannot find symbol in my macOS environment.
According to the latest description in the repo (as of time writing the answer):
To build a distribution for your local OS and print its output location upon completion, run:
./gradlew localDistro
To build a distribution for another platform, run the related command:
./gradlew :distribution:archives:linux-tar:assemble
./gradlew :distribution:archives:darwin-tar:assemble
./gradlew :distribution:archives:windows-zip:assemble
To build distributions for all supported platforms, run:
./gradlew assemble
Distributions are output to distributions/archives.

Resources