Can anyone please tell me if there is any advantage of gradlew over gradle?
Also I have some doubts on the gradle-wrapper.properties file.
Initially when I ran
C:\project_basedir>gradle wrapper
I found the following content in gradle-wrapper.properties file.
#Thu Jun 12 17:06:10 IST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-1.12-bin.zip
To stop downloading the zip file I have followed the steps as suggested in chapter 61.1. Configuration of gradle documentation and added the gradle-1.12-bin.zip file from my local gradle installation to <Project_Base>\gradle\wrapper directory. and modified the properties files as follows:
#Thu Jun 12 17:06:10 IST 2014
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-1.12.zip
It saved the downloading time.
My Gradle installtion structure is as below:
C:\Users\sanjeev\Softwares\Gradle\gradle-1.12\bin
I have set system property GRADLE_USER_HOME to my local installtion dir i.e. C:\Users\sanjeev\Softwares\Gradle\gradle-1.12. But the distributionBase & distributionPath options are not picking the value.
I even tried to modify the values as:
distributionBase=file\:///c:/Users\sanjeev\Softwares\Gradle\gradle-1.12.zip
It did not work.
Exception in thread "main" java.lang.RuntimeException: Base: file:/C:/Users/sanjeev/Softwares/Gradle/gradle-1.12 is unknown
Can someone please suggest what am I missing here?
Or in a nutshell how to define distributionBase,distributionPath,zipStoreBase and zipStorePath properly?
The advantage of gradlew over gradle is that:
You don't have to have gradle installed on your machine in order to build your project.
You can control which version of gradle is needed to build your project.
I'm not sure of the point of changing the distribution url in the properties file. The whole point of the wrapper is that it downloads gradle. If you get it locally you might as well install and use gradle instead. The wrapper will only download the distribution once anyway and store it for each user (hence the use of GRADLE_USER_HOME).
GRADLE_USER_HOME is an environment property, not a system property. If you want to change the gradle user home using system properties you need to set 'gradle.user.home'.
The best way to get a proper gradle-wrapper.properties is to run the wrapper task using gradle wrapper. But that needs a local gradle installation. When editing the content of that file manually you need to be careful with escaping. Try this distributionUrl:
distributionUrl=file\://gradle/wrapper/gradle-1.12-bin.zip
One more comment: It might be easier to maintain if you put your gradle installation in a local bin repository (e.g in your nexus or artifactory repository) and let gradlew download the referenced gradle bin from there. The benefit is, that you just need to update the distributionURL.
If you're trying to change your wrapper distributionUrl to point at your local Gradle.zip file.
(Without spaces) Change it to file \ : ///C:\Users\sanjeev\Softwares\Gradle\gradle-1.12.zip (the filename gradle-1.12.zip here must be the same as how it is in your PC.)
Remove spaces as shown below, or it wont work :
distributionUrl= file\:///c:/Users\sanjeev\Softwares\Gradle\gradle-1.12.zip
Related
I have an off the shelf application that ships a version of gradle with it. It also has scripts that are hard coded to set GRADLE_HOME to this location.
I want to zip up this dir, put it in nexus and replace it with the gradle wrapper.
How do I configure the gradle wrapper to download this zip from nexus and extract it to a specific location in the project?
EDIT: In the gradle-wrapper.properties I have
distributionPath=wrapper/gradle
However, I end up with it being unzipped to
...\wrapper\gradle\gradle-2.3-bin\8gn7esgljqyucijpbynjk93oc\gradle-2.3
How do I get it to unzip to the path I specified and not to the subdirs?
The location to which Gradle gets unpacked is a combination of the distributionBase and distributionPath properties in gradle-wrapper.properties file. The location specified by distributionPath will always be considered as relative to distributionBase. The only available values for distributionPath are GRADLE_USER_HOME and PROJECT. Even when using PROJECT the wrapper will still generate the folder structure you see above.
If you want to control this more precisely I'd suggest not relying on the wrapper to do this and instead add a task to your build specifically for this purpose.
I need to specify the path to javac in my gradle project. I can do this by adding the following to my build.gradle file:
options.forkOptions.executable = '/home/mj/lib/jdk1.7.0_80/bin/javac'
The problem is that this file is shared in our repository and I do not want the setting to get pushed there. I tried putting it in my local gradle.properties file, but it didn't work. Also setting gradle.java.home does not affect this. I guess it's because gradle uses gradle.java.home for java and not for javac, right? I also (hopelessly) tried setting a gradle.jdk.home which (not surprisingly) didn't work either!
Is there any place outside the project that is included in build.gradle?
In your gradle.properties:
javacPath=/home/mj/lib/jdk1.7.0_80/bin/javac
In your build.gradle
options.forkOptions.executable = project.property('javacPath')
Using a path relative to "java.home" has worked for us. Not elegant, but this does not need another setting. The reason why we need this in the first place is that we build with a JDK that's part of the working copy, not pre-installed with the Jenkins slave. We have no javac/JDK on the slave, just a JRE to run the Jenkins slave. Our gradlew in the working copy points to the JDK next to it.
compileJava {
options.fork = true
options.forkOptions.executable = "${System.properties['java.home']}/../bin/javac"
}
(Note: At Java run time, java.home points to the $JAVA_HOME/jre folder within the JDK. That's one below where the JAVA_HOME environment variable points to.)
It's closing in on the end of 2021 and there's a much simpler approach now. In your project's root directory add the following to your gradle.properties file (add the file, too, if it doesn't exist):
org.gradle.java.home=path/to/jdk
My GRADLE_USER_HOME is set to c:\gradle. Android Studio has created C:\gradle\wrapper\dists\gradle-2.2.1-bin\88n1whbyjvxg3s40jzz5ur27 with a copy of gradle v2.2.1, but when I run gradlew.bat from the command line, a new folder C:\gradle\wrapper\dists\gradle-2.2.1-bin\3rn023ng4778ktj66tonmgpbv is created with the exact same files. Why?
I have different Gradle Distributions/Versions, but only in the
C:\Users\MyUsername.gradle\wrapper\dists\gradle-2.3-bin
I have 3 Distributions.
Maybe it can come from different Versions of the gradle-wrapper.jar in the Gradle Wrapper Folder.
Following some Information about the Gradle Wrapper:
In the directory gradle/wrapper parallel to your gradlew and gradlew.bat file is the gradle wrapper jar and a gradle-wrapper.properties file.
In this gradle-wrapper.properties file you define the distribution Url i.E.
distributionUrl=http\://services.gradle.org/distributions/gradle-2.3-bin.zip
to your remote gradle distribution for initial download.
There are -bin an -all gradle Versions.
See http://services.gradle.org/distributions
If you have an other Place of a gradlew with an other gradle-wrapper.properties file with a different -all or -bin Definition
and / or different Versions of the gradle-wrapper.jar,
then maybe you will get two different gradle distributions downloaded.
Prevent it: Only define one same gradle distribution and gradle-wrapper.jar.
There is a similar question here: Gradle properties not being read from ~/.gradle/gradle.properties but it does not solve my problem.
It seems to me that gradle is NOT reading my ~/.gradle/gradle.properties file.
I have a gradle.properties file in ~/.gradle, and it has properties needed to sign artifacts before uploading to maven central. It looks like this:
signing.keyId=12345678
signing.password=myPassword
signing.secretKeyRingFile=/home/me/.gnupg/secring.gpg
sonatypeUsername=me
sonatypePassword=myOtherPassword
When I try to build my project, it complains that there's no sonatypeUsername property, thus:
> Could not find property 'sonatypeUsername' on root project 'yourProject'.
Here's the relevant portion of my project's build.gradle:
uploadArchives {
repositories {
mavenDeployer {
// lots of non-interesting things here
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: project.property("sonatypeUsername"), password: project.property("sonatypePassword"))
}
}
}
}
When I try to build the project with debugging, here's what I see regarding properties:
$ ./gradlew --stacktrace --debug build
[INFO] [o.g.BuildLogger] Starting Build
[DEBUG] [o.g.BuildLogger] Gradle user home: /home/me
[DEBUG] [o.g.BuildLogger] Current dir: /home/me/dev/yourProject
[DEBUG] [o.g.BuildLogger] Settings file: null
[DEBUG] [o.g.BuildLogger] Build file: null
[DEBUG] [o.g.i.b.BuildSourceBuilder] Starting to build the build sources.
[DEBUG] [o.g.i.b.BuildSourceBuilder] Gradle source dir does not exist. We leave.
[DEBUG] [o.g.i.DefaultGradlePropertiesLoader] Found env project properties: []
[DEBUG] [o.g.i.DefaultGradlePropertiesLoader] Found system project properties: []
[DEBUG] [o.g.a.i.a.m.DefaultLocalMavenRepositoryLocator] No local repository in Settings file defined. Using default path: /home/me/.m2/repository
[DEBUG] [o.g.i.ScriptEvaluatingSettingsProcessor] Timing: Processing settings took: 0.286 secs
[INFO] [o.g.BuildLogger] Settings evaluated using empty settings script.
[DEBUG] [o.g.i.ProjectPropertySettingBuildLoader] Looking for project properties from: /home/me/dev/yourProject/gradle.properties
[DEBUG] [o.g.i.ProjectPropertySettingBuildLoader] project property file does not exists. We continue!
[INFO] [o.g.BuildLogger] Projects loaded. Root project using build file '/home/me/dev/yourProject/build.gradle'.
The problem was that I made an assumption that wasn't true. If you look at section 14.2 of the gradle documentation, it says:
You can place a gradle.properties file in the Gradle user home directory (defined by the “GRADLE_USER_HOME” environment variable, which if not set defaults to USER_HOME/.gradle) or in your project directory.
My incorrect assumption was that USER_HOME just defaulted to the standard linux HOME environment variable. This is not true.
As soon as I export USER_HOME=$HOME in my ~/.bashrc everything works
By default, without setting GRADLE_USER_HOME, it should work. I tested it in v3.5.
But make sure if your are running it as the right user. For ex, if you do your ./gradlew build using sudo, then gradle.properties in your home folder will not be picked up.
To make sure the default gradle user home, you can run gradle with the --debug option and look out for the below line,
[DEBUG] [org.gradle.internal.buildevents.BuildLogger] Gradle user home:
I am using Windows and I was experiencing the same issue. I noticed that my ~/.gradle/gradle.properties file had a byte-order-marker (BOM) at the beginning and I think it had windows line endings (\r\n). I recreated my ~/.gradle/gradle.properties file by deleting it and then making a new one with vim with unix line endings (\n) with the same content as before and then it started working. I don't know if it was the BOM, line-endings, or the combination of the two that was causing the issue, but I thought I should share this in case someone else has the same cause for this issue.
A quick and dirty solution is just to simply put the gradle.properties right next to your build.gradle, that will guarantee it will be read. I realize this doesn't solve a single centralized source of common properties, but at least it's something.
I did check Proxy Settings in Android Studio and i had No Proxy selected.
I did Invalidate Cache and Restart with no luck.
I added an exception in Firewall, still no luck.
In project gradle.properties i have no proxy configurations. Its empty, only comments.
In a previous version of Android Studio i had enabled Global Proxy Setting and it was a file stored in my user profile %userprofile%\.gradle\gradle.properties
Removing proxy lines in this file, solved my issue. I had to restart Android Studio to make it work.
:)
I myself stumbled upon this question when I was struggling with apk building via gradlew.
I tried setting Gradle_user_home earlier for the mentioned error in question, but it was of no use, below solution worked for me.
I have below configuration for gradle-wrapper.properties :
*distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip*
gradlew itself at run time downloads the correct distribution of gradle from above config (distributionUrl). Nothing else is required.
I faced the same issue and solved it by using gradle binary, to build, instead of wrapper that comes with android project. You can install gradle from here: https://docs.gradle.org/current/userguide/installation.html#installation
Then used system-wide gradle to build, while on project root, instead of wrapper, like ex:
$ gradle installDebug
I made a different mistake. Why did i set up this field in "intelligent idea"? :) However when i wrote correct value in this field I get correct reading gradle.properties from .gradle
some setting in Idea
Oh I noted that the "project property file does not exists. We continue!" is shown because the script will search for gradle properties in different routes.
it will check both in root/gradle.properties and in root/app/gradle.properties, so it will only add the ones from the one found and display the "error" from the other one.
However in the log you can actually see the properties that were added from the read files:
Adding project properties (if not overwritten by user properties): [android.nonTransitiveRClass, kotlin.code.style, org.gradle.jvmargs, android.useAndroidX]
I'm trying to build a gradle project with gradle-wrapper (gradlew).
When I build with ./gradlew build, it outputs text
Downloading http://services.gradle.org/distributions/gradle-1.11-bin.zip
And I already got gradle-1.11-bin.zip downloaded separately and I don't want to be downloading it again when I build.
So, where shall I put gradle-1.11-bin.zip in my project or system so that I don't have to download again?
gradle/wrapper/gradle-wrapper.properties is as following.
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-1.11-bin.zip
And I've tried copying gradle-1.11-bin.zip into gradle/wrapper/dists which didn't solve the problem.
From gradle-wrapper documentation, I found in section 61.1. Configuration
If you don't want any download to happen when your project is build
via gradlew, simply add the Gradle distribution zip to your version
control at the location specified by your wrapper configuration. A
relative URL is supported - you can specify a distribution file
relative to the location of gradle-wrapper.properties file.
So, I changed distributionUrl property in gradle/wrapper/gradle-wrapper.properties to
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=gradle-1.11-bin.zip
Then, I made a copy of gradle-1.11-bin.zip in gradle/wrapper/.
Then, ./gradlew build downloaded local copy of zip and built the project.
Here's a real-world example:
mkdir -p $HOME/dev
cd $HOME/dev
git clone https://github.com/oss-review-toolkit/ort
cd ort/gradle/wrapper
wget https://services.gradle.org/distributions/gradle-7.5.1-bin.zip
sed -i 's/distributionUrl=.*/distributionUrl=gradle-7.5.1-bin.zip/' gradle-wrapper.properties
cd ../..
./gradlew installDist
Modifty the gradle/gradle-wrapper.properties
Windows:
distributionUrl=file\:/d:/gradle-2.2.1-all.zip
linux:
distributionUrl=file\:/tmp/gradle-2.2.1-all.zip
Just drag downloaded gradle file in your browser address bar and then copy address from address bar and change gradle/wrapper/gradle-wrapper.properties as following:
distributionUrl=ADDRESS THAT COPY FROM YOUR BROWSER
example:
distributionUrl=file:///E:/gradle/gradle-4.1-all.zip
or you can copy gradle.zip file to wrapper folder then use relative path:
distributionUrl=gradle.zip
This is what I did to avoid editing all gradle wrapper for current and future projects.
Locate your gradle-wrapper.properties in your project folder (eg. ./gradle/wrapper/gradle-wrapper.properties)
open the file with a text editor like Sublime Text to locate the distributionUrl line (eg. distributionUrl=http\://services.gradle.org/distributions/gradle-2.10-bin.zip
The gradle binary archive needed is gradle-2.10-bin.zip. Another version is gradle-2.10-all.zip that includes everything including source code and documentation.
Please note each project ships with different versions of gradle distributions and you can change the version to the one you have (gradle-x.xx-XXX.zip) that include the binary. (eg. gradle-2.11-bin.zip | gradle-2.11-all.zip ).
Execute gradlew.bat on window or gradle on linux to start the wrapper to build the project.
It will begin downloading the gradle-2.10-bin.zip to the .gradle\wrapper\dists in your home directory (eg.C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-bin). This download happens just once for each specified gradle version.
If you already downloaded the archive before you can terminate the download using Ctrl+C
Go into the gradle download location C:\Users\Sojimaxi\.gradle\wrapper\dists\gradle-2.10-all\78v82fsf226usgvgh7q2ptcvif copy your own copy of gradle-2.10-bin.zip into that directory then delete the gradle-2.10-all.zip.part in that directory.
That's all. Go back to your project directory to execute gradlew.bat and it will use your local copy instead of downloading a new one.
This solution didn't work for me but help me to get the right way so if you want install gradle offline follow these steps:
1- at your project under gradle directory open this file (gradle-wrapper.properties)
2- at last line you will find the gradle version, download that version or copy the file from another pc
distributionUrl=http\://services.gradle.org/distributions/gradle-3.3-bin.zip
Download Link will be like this: http://services.gradle.org/distributions/gradle-3.3-bin.zip
3- open this location
C:\Users\userName.gradle\wrapper\dists\gradle-3.3-all
and ensure that is only one folder (the name doesn’t matter it different at devices) if there any other folders delete all of them and press gradle sync on android studio which will generate another folder automatic with a random name.
4- open that folder and ensure that has only the last two files in the screenshot.
5- move the zip file that you downloaded into that folder
6- press sync gradle on android studio again suppose that gradle will work fine.
I found another easiest way to do this just started my XAMPP server and then made a folder gradle inside htdocs. I added the zipped file gradle-4.4-all.zip inside that folder. Changed the distribution url to distributionUrl=http\://localhost/gradle/gradle-4.4-all.zip
I restarted android and the syncing completed without any issue.
copy your path wher you put the file gradle-5.0-rc-5-bin.zip
example:
path C:/My doc/tools
if you have some spaces in your path change it with %20
file:///C:/My%20doc/tools/gradle-5.0-rc-5-bin.zip
and execute the command:
$ gradlew wrapper --gradle-version 5.0-rc-5
I download to
C:\data\Setup\Development\Gradle 2.11\gradle-2.11-all.zip
inside Eclipse, I declare:
Then I create new Gradle project (with wrapper) very fast, no need download. (Easy more than this solution)
create local server to mock https download(maybe a little complex),but it work
1. install tomcat then unzip and exec E:\apache-tomcat-8.5.4\bin\startup.bat
2.put gradle-2.14.1-all.zip to E:\apache-tomcat-8.5.4\webapps\ROOT\distributions
3.change url like this distributionUrl=http\://localhost:8080/distributions/gradle-2.14.1-all.zip
now run as usual
// Do not use android 8 as it will keep downloading grade distribution use grade 7
ionic cordova platform add android#8.0.0
// This will run
ionic cordova platform add android#~7.1.1 --save
Then run below and this time it should get success( Worked for me)
ionic cordova build android