是Gradles`jar`的方法? [英] Is Gradles `jar` a method?

查看:206
本文介绍了是Gradles`jar`的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的Java插件的摇篮

I'm using the Java Plugin in Gradle

apply plugin: 'java'

我也用配置的Jar任务:

I also configure the Jar-task using:

version = '1.0'
jar {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version
    }
}

如果我的理解是正确的, JAR 方式这就是所谓的一个封闭作为参数。但如果是这种方法记录?我在我的understandung它舒尔德是项目的方法。

If I understood it right, jar is a method which is called with a closure as the parameter. But where is this method documented? I my understandung it schuld be a method of Project.

我无法在 https://docs.gradle.org/current找到它/userguide/java_plugin.html https://开头docs.gradle.org/current/dsl/org.gradle.api.Project.html 并的 https://docs.gradle.org/current/dsl/org.gradle.api.tasks.bundling.Jar.html

还是我错了我的假设,即 JAR 是一个方法?

Or am I wrong with my assumption that jar is a method?

推荐答案

答案是: yes和no 。语法的语法糖的(尽管在这种情况下,它使事情变得混乱)。这是不是一个函数 JAR 被称为,但功能 tasks.getByName ,获取名称和闭包一个参数。

The answer is yes and no. The syntax is syntactic sugar (although in this case it makes things confusing). It is not a function jar that is called, but the function tasks.getByName that gets the name and the closure as a parameter.

https://docs.gradle.org/current/userguide/more_about_tasks.html 它说部分 17.3。配置任务例17.9配置任务 - 与闭合):

这适用于任何任务。例子3号线是只为快捷方式tasks.getByName()方法。需要注意的是,如果你传递一个封闭的 GetByName方法()方法,这种封闭适用于配置的任务是很重要的,而不是在执行任务。

This works for any task. Line 3 of the example is just a shortcut for the tasks.getByName() method. It is important to note that if you pass a closure to the getByName() method, this closure is applied to configure the task, not when the task executes.

所以,你也可以这样写:

So you can also write:

version = '1.0'
tasks.getByName "jar", {
    manifest {
        attributes 'Implementation-Title': 'Gradle Quickstart',
                   'Implementation-Version': version
    }
}

这篇关于是Gradles`jar`的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆