理解 Gradle 项目中的流程

huangapple go评论79阅读模式
英文:

Understanding the flow in Gradle project

问题

Completed:

我纯粹来自Maven背景,到目前为止还没有使用过Gradle构建。

Completed :

  1. 我能够成功地构建这个项目 https://github.com/opendistro-for-elasticsearch/anomaly-detection,使用 ./gradlew build 命令。

  2. 根据项目文档,提到 ./gradlew :run 命令将启动一个安装了两个插件的单节点 Elasticsearch 集群。我尝试过,能够像下面这样安装这两个插件:

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

理解 Gradle 项目中的流程

Question :

现在我正试图理解这个开源代码,

  1. 在 build.gradle 中,这四个标签的目的是什么(https://github.com/opendistro-for-elasticsearch/anomaly-detection):buildscript、plugins、repositories、ext

  2. 当我查看 build.gradle 时,似乎调用了以下包进行构建,

    allprojects {
    group = 'com.amazon.opendistroforelasticsearch'

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

    }

    但是在这个代码(https://github.com/opendistro-for-elasticsearch/anomaly-detection)中,主方法/触发点在哪里呢?是否有人可以查看这个 GitHub 项目,并告诉我代码的起始点,这样我就可以调试并获取其余的上下文了!!

理解 Gradle 项目中的流程

非常感谢任何帮助!

谢谢,
Harry

英文:

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

理解 Gradle 项目中的流程

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!!

理解 Gradle 项目中的流程

Any help is appreciated!

Thanks,
Harry

答案1

得分: 1

关于Gradle的问题,我想它们可以很容易地得到解答:

  1. 这四个标签的目的是什么:

    • buildscript:该块允许在加载构建脚本的其余部分之前进行设置。例如,这可以用于将插件添加到类路径中。但是这个用例已经过时了,推荐使用plugins块。(文档)
    • plugins:使用此块,您可以向Gradle项目添加插件。id 'java' 对于Java项目是典型的。这些插件可以随同Gradle一起提供,也可以从远程仓库检索。如果需要,可以在setting.gradle文件中进行配置。(文档)
    • repositories:为了从远程仓库解析(和推送)构件,您需要定义这些仓库。一个常见的选择是 mavenCentral()jcenter(),但您也可以定义自己的仓库。在防火墙后面进行企业使用时,我们经常这样做。(文档)
    • ext:这是Gradle项目的扩展,允许您为整个构建脚本定义附加属性。一旦定义,您可以在不使用ext.前缀的情况下访问它们。(文档)
  2. allprojects 对根项目和所有子项目进行迭代,并对每个项目应用闭包。在这种情况下,将组设置为给定的字符串,并且存储一个命令,该命令在Java插件应用于该项目并将Java输入和输出设置为版本1.8时执行。

至于主方法:我猜您将不得不在项目中搜索主方法。或者,它可能是启动应用程序的框架。在这种情况下,必须存在某种挂钩(重写的类/实现的接口,注解?),用于框架启动您的实际应用程序。您将不得不在框架文档中检查这一点。快速入门指南可能是开始查找的好地方。

英文:

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.

huangapple
  • 本文由 发表于 2020年9月3日 02:15:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/63711396.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定