How Do You Specify Where The Gradle Wrapper Installs Gradle? - gradle

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.

Related

What does Gradle do with the files, which are located in src/main/resources directory?

I'm trying to figure out, what Gradle does with the files, which are located in src/main/resources directory.
The processResources task, added by the java plugin to the project, copies them to the build/resources/main directory.
The content of this directory is bundled into the jar file created by the jar task that is also added by the java plugin, and the resources can thus be loaded, at runtime, by the ClassLoader.
See the documentation of the java plugin.
it might do nothing with them, but ignore them - per default (with the Android plugin) that directory is called res, only the Java plugin would take the resources directory into account (the question does not indicate which plugin is used). otherwise it would run a processResources task on them; only res/raw is not being processed (copied 1:1).

Where m2 file is stored when installing apache maven on a unix box

I downloaded maven gz file, unzipped same, but i dont know where the m2 is stored. I imagine im missing a step but i cant see what one?
Is there aninstall script etc?
[root#atddpvm5 apache-maven-3.5.4]# cd /var/tmp/apache-maven-3.5.4/
[root#atddpvm5 apache-maven-3.5.4]# ls
apache-maven DEPENDENCIES doap_Maven.rdf LICENSE maven-builder-
support maven-core maven-model maven-plugin-api
maven-resolver-provider maven-settings-builder NOTICE README.md
CONTRIBUTING.md deploySite.sh Jenkinsfile maven-artifact maven-compat
maven-embedder maven-model-builder maven-repository-metadata maven-
settings maven-slf4j-provider pom.xml src
By default the .m2 folder is stored in the home folder of the user. In this case since you are using root, the path is most likely /root/.m2. You also have to use the -a switch with ls to see that folder, since it's a hidden folder (it starts with a .). Note that the folder will only be created on the first usage of Maven, i.e. when you call a maven command on a maven project, like mvn clean install.
Additionally it looks like you have downloaded the source distribution of Maven, which only makes sense if you want to work on Maven itself. You might want to download the binary distribution, if you just want to use it.

Downloaded path for Gradle comple statement [duplicate]

How does Gradle store downloaded jar files on the local file system? Maven stores them in the .m2 directory under USER_HOME, but where does Gradle store them? I checked the .gradle folder there, but saw only compiled scripts.
On Mac, Linux and Windows i.e. on all 3 of the major platforms, Gradle stores dependencies at:
~/.gradle/caches/modules-2/files-2.1
Gradle caches artifacts in USER_HOME/.gradle folder. The compiled scripts are usually in the .gradle folder in your project folder.
If you can't find the cache, maybe it's because you have not cached any artifacts yet. You can always see where Gradle has cached artifacts with a simple script:
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.guava:guava:12.0'
}
task showMeCache doLast() {
configurations.compileClasspath.each { println it }
}
Now if you run gradle showMeCache it should download the dependencies into the cache and print the full path.
In Windows 10 PC, it is saved at:
C:\Users\%USERNAME%\.gradle\caches\modules-2\files-2.1\
Gradle's local repository folder is:
$USER_HOME/.gradle/caches/modules-2/files-2.1
Defined dependencies will be loaded from remote repositories into gradle's local repository folder. For each loaded file, gradle will be create a new folder named with md5 value of the original file (pom,jar,..). Full path for the dependency file is made up from :
groupid + artifactid + version + FILE_MD5_VALUE + FILE_NAME
If our defined dependency is:
compile 'org.springframework:spring-jdbc:4.3.4.RELEASE'
Then the library will be loaded into :
/$USER_HOME/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jdbc/4.3.4.RELEASE/42175d194cf6aa7c716c0887f30255e5c0a5262c/spring-jdbc-4.3.4.RELEASE.jar
In fact the cache location depends on the GRADLE_USER_HOME environment variable value.
By default, it is $USER_HOME/.gradle on Unix-OS based and %userprofile%.\gradle on Windows.
But if you set this variable, the cache directory would be located from this path.
And whatever the case, you should dig into caches\modules-2\files-2.1 to find the dependencies.
If you want your dependency files to be in some specific folder you can simply use a copy task for it. For Eg.
task copyDepJars(type: Copy) {
from configurations.compile
into 'C:\\Users\\athakur\\Desktop\\lib'
}
I am on windows,
You should be able find the dependencies inside
$USER_HOME.gradle\caches\artifacts-24\filestore
Many answers are correct!
I want to add that you can easily find your download location with
gradle --info build
like described in https://stackoverflow.com/a/54000767/4471199.
New downloaded artifacts will be shown in stdout:
Downloading https://plugins.gradle.org/m2/org/springframework/boot/spring-boot-parent/2.1.7.RELEASE/spring-boot-parent-2.1.7.RELEASE.pom to /tmp/gradle_download551283009937119777bin
In this case, I used the docker image gradle:5.6.2-jdk12.
As you can see, the docker container uses /tmp as download location.
You can use the gradle argument --project-cache-dir "/Users/whatever/.gradle/" to force the gradle cache directory.
In this way you can be darn sure you know what directory is being used (as well as create different caches for different projects)
I just stumbled onto this while searching for this answer. If you are using intellij, you can navigate to the file location, but opening the external lib folder in the project explorer, right clicking on the jar, and select Open Library Settings.
It took me a while to realize this, hence the additional answer. Hopefully it can save folks time. Note that if you are running sudo gradle the dependencies may not be in your home directory, even if sudo echo $HOME returns /Users/<my-non-root-user>/. On my Mac, Gradle was caching the dependencies in /private/var/root/.gradle/caches/.
In case it is an Android gradle project - you can find the android libraries below your $ANDROID_HOME/extras/android/m2repository folder
In android studio do the following steps to check the gradle downloaded jar file.
Set project structure view to "Project"
At bottom External library section available, expand it.
Here you can see downloaded jar files.
On my windows machine with "Buildship 2.0.2" plugin installed in eclipse, dependencies are stored :
$USER_HOME.gradle\caches\modules-2\files-2.1
For my case, I was using an Ivy repository, and my Gradle dependencies were stored in ~/.ivy2/.

Gradle wrapper ignores already installed distribution?

The gradle wrapper distributions are located on my machine under:
C:\Users\Ruperto.gradle\wrapper\dists\gradle-2.10-all
In this folder I already had 2 folder with long names (78v82fsf226usgvgh7q2ptcvif, a4w5fzrkeut1ox71xslb49gst) and now after running gradlew in the command line of Windows it downloaded the same version again and added a new folder to the above path, all of the 3 folders now have the same gradle version inside, same size also, why is this happening?
Gradle Wrapper is downloaded from distribution URL.
If you do not specify the distribution URL, default URL will be used, e.g. https://services.gradle.org/distributions/.
Gradle Wrapper binary is always downloaded once per distribution URL, even if it is exactly the same binary file and it is stored in a directory that is basically hash of the distribution URL.

How to use gradle zip in local system without downloading when using gradle-wrapper

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

Resources