Understanding the flow in Gradle project

313 views Asked by At

I am purely from the Maven background, I haven't used the Gradle build so far.

Completed :

  1. I am able to successfully build this project https://github.com/opendistro-for-elasticsearch/anomaly-detection using the ./gradlew build

  2. As per the documentation in the project, It is mentioned that ./gradlew :run command will launch a single node elastic search cluster with the two plugins installed. I tried and I am able to get both the plugins installed like below

    http://127.0.0.1:9200/_cat/plugins?v&s=component&h=name,component,version,description

name        component                    version           description
integTest-0 opendistro-anomaly-detection 1.10.0.0          Amazon opendistro elasticsearch anomaly detector plugin
integTest-0 opendistro-job-scheduler     1.10.0.0-SNAPSHOT Open Distro for Elasticsearch job schduler plugin

Question :

Now I am trying to understand this opensource code,

  1. What is the purpose of these four tags in build.gradle (https://github.com/opendistro-for-elasticsearch/anomaly-detection) : buildscript, plugins, repositories, ext

  2. when I look at the build.gradle, It seems that the following package is called for building,

    allprojects { group = 'com.amazon.opendistroforelasticsearch'

     plugins.withId('java') {
         sourceCompatibility = targetCompatibility = "1.8"
     }
    

    }

But where is the main method/trigger point for this code (https://github.com/opendistro-for-elasticsearch/anomaly-detection) ? Could someone look at this github project and let me know the starting point of the code so that I will debug and get the remaining context please!!

enter image description here

Any help is appreciated!

Thanks,
Harry

1

There are 1 answers

2
J. Buehler On

Regarding the Gradle questions, I guess they can be answered easily:

  1. What is the purpose of these four tags:

    • buildscript: This block allows to make settings that are applied BEFORE the rest of the build script is loaded. For example, this can be useful to add plugins to the classpath. But that usecase is outdated and the use of the plugins block is recommended. (Documentation)
    • plugins: With this block you add plugins to the Gradle project. id 'java' is typical for Java projects. The plugins are either shipped with Gradle or will be retrieved from remote repositories. This can be configured in the setting.gradle file if required. (Documentation)
    • repositories: In order to resolve artifacts from remote repositories (and push to them) you'll have to define these repos. A popular choice is mavenCentral() and jcenter(), but you can also define your own repos. For corporate use behind firewall we do that a lot. (Documentation)
    • ext: This is an extension to the Gradle project that allows you to define additional properties for use throughout the build script. Once defined, you can access them without the ext. prefix. (Documenation)
  2. allprojects iterates over the root project and all subprojects and applies the closure to each project. In this case the group is set to the given string and a command is stored that is executed when Java plugin is applied to that project and sets Java input and output to version 1.8.

As for the main method: I guess you'll have to search the project for a main method. Alternatively, it could be the framework that starts your application. In that case there must be some kind of hook (Overwritten class/implemented interface, Annotation?) for the Framework to start your actual application. You'll have to check that in the framework documentation. Quick start guides could be a great place to start looking.