DEV Community

Discussion on: Two Gradle questions I have.

Collapse
 
sierisimo profile image
Sinuhe Jaime Valencia

Sorry I'm late to the party!

Let me give some not requested context and then, we move to your question.

Gradle is a build tool of "general purpose" which means it doesn't have an specific way for build stuff, so how does it build things? with plugins! Each plugin has their own set of definitions and tasks that helps you build stuff, officially Gradle has support for

  • Java (and some JVM languages like Groovy, Kotlin and Scala)
  • C++
  • Swift
  • Partial support for NodeJS

So for any kind of thing you want to build, you will need a plugin or define a task that gives gradle context/idea on how to build things.

Using plugins

For adding an official plugin in your project, you have 2 ways of doing it:

The old way:

apply plugin: NAME_OF_THE_PLUGIN

The fancy and new way:

plugins {
   java
}
Enter fullscreen mode Exit fullscreen mode

The main difference is that the old way allows you to apply more things than just plugins (other build files for example) while the new way only support applying plugins already present and defined in the classpath (if you don't understand what it is, just leave as "official plugins")

You have the option for adding plugins and leverage the build/test process to them. In your case you have 2 options:

  • java
  • application

For the case of the java plugin, this is the simplest plugin for java projects, it requires a lot of manual configurations and gives you the basics of building java.

application is a fancier plugin, that includes java plugin and also gives you the possibility of configure where your main is located, once configured, you will have a new task for running that main method using:

gralde run

Is a more suitable plugin as it adds some useful tasks for testing and running java code.

You can add multiple plugins to your build process, and even create your own, there's also a plugin search page and the official docs that sometime are a little hard to navigate...

Hope this helps!

Collapse
 
baenencalin profile image
Calin Baenen

Thanks for this.
I wanted to respond sooner but didn't find the time.

Have a wonderful day.
Cheers.