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
Related
What's the gradle equivalent for mvn clean eclipse:clean?
I'm looking to delete files created by Eclipse through command. Is this possible?
If you are using one of the Gradle Eclipse Plugins (plugins { id 'eclipse' }), you can delete all Eclipse-specific files using the task cleanEclipse. Since the task clean from the Gradle Java plugin acts as an eqiuvalent to mvn clean, you could use the following command to achieve a similar behavior.
gradle clean cleanEclipse
Please note that there is no one-to-one mapping between Maven functionality and Gradle functionality, so there may be files affected or not affected by one command or the other.
As others have already suggested, you should ignore files you will never want to push to version control by using the respective version control feature (e.g. a .gitignore file when using Git).
I have created a project using gradle and have created a gradle wrapper. How can I make sure that the project builds and runs on machine who don't have gradle installed?
If you created the project using gradle (i.e. gradle init), then gradle should have placed a gradlew, or gradlew.bat file in the root directory of your project. Use those files to run gradle on another machine.
gradlew can be used on *nix machines, while gradlew.bat is used on windows.
In any case, gradle also creates a gradle/wrapper which contains the gradle jar, and this can be run on any system which has java installed.
See: Difference between using gradlew and 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
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.
I am new to playorm and gradle. My goal is to get playorm compiled (especially play 2.1 plugin) and deployed to local nexus repository manager.
What gradle tasks should I invoke to do this?
I tried to run gradlew clean assemble - creates workspace*.jar in output/libs so I assume build part was done. How to get these artefacts renamed and uploaded to my nexus?
https://github.com/deanhiller/playorm
You'll want to read this chapter of the user guide. It looks like the only repository configured for playorm is Maven Central, but the user guide tells you how to configure your own repository and interact with it. After following the guide, if you have a more specific question ask again here.
I created local.gradle and included it in build.gradle to create uploadArchives task using standard gradle upload procedure.
build.gradle was modified in upstream version to include local.gradle if exists.