Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java

When I am creating my own project in Intellij which Gradle files I need by default

Files needed

4 Answers

Nice question. Will try my best

Overview

To run Gradle Project you need

  • Wrapper jar and its properties
  • Build Gradle file
  • Settings file
  • script runners, to run from terminal

Gradle Wrapper and Properties

Wrapper is a tool for running Gradle when you don't have Gradle installed. That is why you have this gradle-wrapper.jar file that executed as simple java app java -jar gradle-wrapper.jar for example in gradlew script see below.

The Gradle Wrapper itself and properties for gradle wrapper, that will be downloaded they have to be in gradle/wrapper directory

gradle/wrapper/gradle-wrapper.jar
gradle/wrapper/gradle-wrapper.properties

Properties file is small, usually looks like this

#Fri Sep 09 20:02:42 CEST 2016
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-all.zip

If you want to know which option is which, please visit this docs page

build.gradle file

This is one of the main file, where we define, what dependencies we use. That is the file we mostly interact with. Needles to say, you know what to write there.

settings.gradle

This file by default just defines project name. If you git clone-d project, and Import it as gradle project you can change for example project name there, and then IDE will pick up this name and will use it and show everywhere.

When generated by Intellijdea it looks like this

rootProject.name = 'your-project-name'

For more options see this docs page

Gradle run scripts

If you want to run gradle project without intellijdea, for example on some server. And you haven't yet deployed your Java App as JAR or WAR, you can simply use the two files below.

  • gradlew.bat (Windows)
  • gradlew (Unix-like)

You can simply go with terminal or console to project directory and run

./gradlew

On Unix-like systems, you may also see Permission Denied message. In this case make file executable using chmod +x gradlew and then run again.

Or for Windows

gradlew.bat

PS

Looks like that is it.

You may also see .gradle directory when you run the project, however this folder contains all downloaded dependencies, cache and etc, so there is no need to keep it in git or anywhere. It will be generated by Gradle for you.

I hope I understood your question correctly...

First of all alexander, you understood my question quite fairly. So by default, when you create a project gradlew and gradlew.bat are not present, they are not needed if you are using IntelliJ o. I understand which version to use where.

Yes if you run project from Intellijdea you don't need in principle to keep files gradlew and gradlew.bat in project.

But I'd recommend you keep this files, just in case. It is also recommended by Official Gradle Wrapper Docs

If a Gradle project has set up the Wrapper (and we recommend all projects do so), you can execute the build using one of the following commands from the root of the project:

./gradlew <task> (on Unix-like platforms such as Linux and Mac OS X)

gradlew <task> (on Windows using the gradlew.bat batch file)

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.

IDEs When importing a Gradle project via its wrapper, your IDE may ask to use the Gradle 'all' distribution. This is perfectly fine and helps the IDE provide code completion for the build files.

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. Just use the appropriate syntax from above whenever you see a command line starting with gradle ... in the user guide, on Stack Overflow, in articles or wherever.

For completeness sake, and to ensure you don’t delete any important files, here are the files and directories in a Gradle project that make up the Wrapper:

gradlew (Unix Shell script)

gradlew.bat (Windows batch file)

gradle/wrapper/gradle-wrapper.jar (Wrapper JAR)

gradle/wrapper/gradle-wrapper.properties (Wrapper properties)

If you’re wondering where the Gradle distributions are stored, you’ll find them in your user home directory under $USER_HOME/.gradle/wrapper/dists.

Thanks Alexander for explaining this so briefly... I will pop up if I need any other answers

Alexander, I was creating this project on spark and a gradle and .gradle file was not present so I copied it in the folder from some other project. I am trying to resolve this error

Error SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

I tried to import the dependency manually by

compile org.slf4j:slf4j-log4j12:1.7.21 but it gives the same error above

There is some version problem but where

It is not the Gradle problem.

It is a Spark Problem.

Checkthis here

You have to find section "How do I enable logging?"

and add proper dependencies logging

see this my project build.gradle