Gradle Programming TODEPLETE: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 8: Line 8:
{{Internal|Groovy#Overview|Groovy}}
{{Internal|Groovy#Overview|Groovy}}


=Inter-Project "Communication"=
=Projects=
 
==Inter-Project "Communication"==


The [[Gradle Concepts#Project|Project]] is the main API to use to interact with Gradle, so a great deal of custom configuration can be achieved getting a hold of a project reference and reading state from it or invoking into it from the build.gradle files. The reference to the current project can be obtained by using getProject() in the corresponding build.gradle file, which is equivalent with invoking 'project'
The [[Gradle Concepts#Project|Project]] is the main API to use to interact with Gradle, so a great deal of custom configuration can be achieved getting a hold of a project reference and reading state from it or invoking into it from the build.gradle files. The reference to the current project can be obtained by using getProject() in the corresponding build.gradle file, which is equivalent with invoking 'project'
Line 28: Line 30:
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
println parent
println parent
</syntaxhighlight>
=Tasks=
==Obtaining a Task Reference==
<syntaxhighlight lang='groovy'>
Task task = project.getTasksByName("build", false).asList().get(0)
</syntaxhighlight>
</syntaxhighlight>



Revision as of 06:55, 24 February 2019

Internal

Groovy

Groovy

Projects

Inter-Project "Communication"

The Project is the main API to use to interact with Gradle, so a great deal of custom configuration can be achieved getting a hold of a project reference and reading state from it or invoking into it from the build.gradle files. The reference to the current project can be obtained by using getProject() in the corresponding build.gradle file, which is equivalent with invoking 'project'

println project

A project reference can be used to get references to other Projects in the tree and thus navigate the hierarchy.

For all projects in the hierarchy, the reference to the root project can be obtained by invoking 'project.getRootProject()', or simply 'rootProject'.

println rootProject

For a sub-project, a reference to the parent project can be obtained by invoking 'project.getParent()', or simply 'parent'.

println parent

Tasks

Obtaining a Task Reference

Task task = project.getTasksByName("build", false).asList().get(0)

Recipes

Task that Prints the Execution Classpath

Print the Runtime Classpath

Obtain and Use Gradle Version in build.gradle

Gradle Object - Gradle Version