ग्रेडल - एक निर्माण चल रहा है

ग्रैड लिपि का निर्माण करने के लिए कमांड लाइन प्रदान करता है। यह एक बार में एक से अधिक कार्य निष्पादित कर सकता है। यह अध्याय बताता है कि विभिन्न विकल्पों का उपयोग करके कई कार्यों को कैसे निष्पादित किया जाए।

एकाधिक कार्य निष्पादित करना

आप एक निर्माण फ़ाइल से कई कार्यों को निष्पादित कर सकते हैं। ग्रैडल हैंडल का उपयोग करके फाइल का निर्माण कर सकता हैgradle command। यह आदेश प्रत्येक कार्य को इस क्रम में संकलित करेगा कि वे सूचीबद्ध हैं और प्रत्येक कार्य को विभिन्न विकल्पों का उपयोग कर निर्भरता के साथ निष्पादित करते हैं।

Example- चार कार्य हैं - task1, task2, task3 और task4। टास्क 3 और टास्क 4 टास्क 1 एंड टास्क 2 पर निर्भर करता है। निम्नलिखित आरेख पर एक नज़र डालें।

उपर्युक्त 4 कार्यों में एक दूसरे पर निर्भर एक तीर के प्रतीक के साथ प्रतिनिधित्व किया गया है। निम्नलिखित कोड पर एक नज़र डालें। कॉपी में पेस्ट कर सकते हैंbuild.gradle फ़ाइल।

task task1 << {
   println 'compiling source'
}

task task2(dependsOn: task1) << {
   println 'compiling unit tests'
}

task task3(dependsOn: [task1, task2]) << {
   println 'running unit tests'
}

task task4(dependsOn: [task1, task3]) << {
   println 'building the distribution'
}

आप उपरोक्त कोड को कार्य के संकलन और क्रियान्वयन के लिए उपयोग कर सकते हैं।

C:\> gradle task4 test

आउटपुट:

:task1
compiling source
:task2
compiling unit tests
:task3
running unit tests
:task4
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs

टास्क को छोड़कर

कार्य को निष्पादन से बाहर करते समय आप ग्रेड कमांड के साथ -x विकल्प का उपयोग कर सकते हैं और कार्य के नाम का उल्लेख कर सकते हैं, जिसे आप बाहर करना चाहते हैं।

उपरोक्त स्क्रिप्ट से टास्क 4 को बाहर करने के लिए निम्न कमांड का उपयोग करें।

C:\> gradle task4 -x test

आउटपुट:

:task1
compiling source
:task4
building the distribution

BUILD SUCCESSFUL

Total time: 1 secs

जब एक विफलता का निर्माण जारी है

ग्रैड निष्पादन को निरस्त कर देगा और किसी भी कार्य के विफल होते ही बिल्ड को विफल कर देगा। विफलता होने पर भी आप निष्पादन जारी रख सकते हैं। इसके लिए आपको gradle कमांड के साथ -continue विकल्प का उपयोग करना होगा। यह प्रत्येक कार्य को उनके आश्रितों के साथ अलग से संभालता है। और मुख्य महत्वपूर्ण बिंदु यह है कि निर्माण के निष्पादन के अंत में प्रत्येक सामना करना पड़ा विफलता और रिपोर्ट को पकड़ना होगा। मान लीजिए कि यदि कोई कार्य विफल हो जाता है तो आश्रित परवर्ती कार्यों को भी निष्पादित नहीं किया जाएगा।

कौन से बिल्ड टू एक्ज़ेक्यूट का चयन करना

जब आप वर्गीकृत कमांड चलाते हैं, तो यह वर्तमान निर्देशिका में एक बिल्ड फ़ाइल की तलाश करता है। पूर्ण पथ के साथ-साथ किसी विशेष बिल्ड फ़ाइल का चयन करने के लिए -b विकल्प का उपयोग कर सकते हैं। निम्नलिखित उदाहरण से एक परियोजना हैलो का चयन करनाmyproject.gradle फ़ाइल जो में स्थित है subdir/ इस पर गौर करें।

task hello << {
   println "using build file '$buildFile.name' in '$buildFile.parentFile.name'."
}

उपरोक्त स्क्रिप्ट को निष्पादित करने के लिए आप निम्न कमांड का उपयोग कर सकते हैं।

C:\> gradle -q -b subdir/myproject.gradle hello

आउटपुट:

using build file 'myproject.gradle' in 'subdir'.

निर्माण जानकारी प्राप्त करना

ग्रैड कार्य और परियोजना के बारे में जानकारी के विवरण को पुनः प्राप्त करने के लिए कई अंतर्निहित कार्य प्रदान करता है। यह संरचना और आपके निर्माण की निर्भरता और डिबगिंग समस्याओं के लिए समझने के लिए उपयोगी हो सकता है। आप अपने प्रोजेक्ट में कार्यों को जोड़ने के लिए प्रोजेक्ट रिपोर्ट प्लगइन का उपयोग कर सकते हैं, जो इन रिपोर्टों को उत्पन्न करेगा।

लिस्टिंग परियोजनाओं

आप चयनित प्रोजेक्ट के प्रोजेक्ट पदानुक्रम और उनके उप प्रोजेक्ट्स का उपयोग करके सूचीबद्ध कर सकते हैं gradle –q projectsआदेश। यहाँ उदाहरण है, बिल्ड फ़ाइल में सभी प्रोजेक्ट को सूचीबद्ध करने के लिए निम्न कमांड का उपयोग करें।

C:\> gradle -q projects

आउटपुट:

------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'projectReports'
+--- Project ':api' - The shared API for the application
\--- Project ':webapp' - The Web application implementation

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :api:tasks

रिपोर्ट निर्दिष्ट होने पर प्रत्येक प्रोजेक्ट का विवरण दिखाती है। आप विवरण निर्दिष्ट करने के लिए निम्न आदेश का उपयोग कर सकते हैं। इसमें पेस्ट करेंbuild.gradle फ़ाइल।

description = 'The shared API for the application'

लिस्टिंग के कार्य

आप निम्न कमांड का उपयोग करके उन सभी कार्यों को सूचीबद्ध कर सकते हैं जो कई परियोजनाओं से संबंधित हैं।

C:\> gradle -q tasks

आउटपुट:

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Default tasks: dists

Build tasks
-----------
clean - Deletes the build directory (build)
dists - Builds the distribution
libs - Builds the JAR

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'projectReports'.
components - Displays the components produced by root project 'projectReports'. [incubating]
dependencies - Displays all dependencies declared in root project 'projectReports'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
help - Displays a help message.
model - Displays the configuration model of root project 'projectReports'. [incubating]
projects - Displays the sub-projects of root project 'projectReports'.
properties - Displays the properties of root project 'projectReports'.
tasks - Displays the tasks runnable from root project 'projectReports' 
   (some of the displayed tasks may belong to subprojects).

To see all tasks and more detail, run gradle tasks --all

To see more detail about a task, run gradle help --task <task>

सभी कार्यों की जानकारी प्रदर्शित करने के लिए आप निम्न कमांड का उपयोग कर सकते हैं।

C:\> gradle -q tasks --all

आउटपुट:

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Default tasks: dists

Build tasks
-----------
clean - Deletes the build directory (build)
api:clean - Deletes the build directory (build)
webapp:clean - Deletes the build directory (build)
dists - Builds the distribution [api:libs, webapp:libs]
   docs - Builds the documentation
api:libs - Builds the JAR
   api:compile - Compiles the source files
webapp:libs - Builds the JAR [api:libs]
   webapp:compile - Compiles the source files

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
buildEnvironment - Displays all buildscript dependencies declared in root project 'projectReports'.
api:buildEnvironment - Displays all buildscript dependencies declared in project ':api'.
webapp:buildEnvironment - Displays all buildscript dependencies declared in project ':webapp'.
components - Displays the components produced by root project 'projectReports'. [incubating]
api:components - Displays the components produced by project ':api'. [incubating]
webapp:components - Displays the components produced by project ':webapp'. [incubating]
dependencies - Displays all dependencies declared in root project 'projectReports'.
api:dependencies - Displays all dependencies declared in project ':api'.
webapp:dependencies - Displays all dependencies declared in project ':webapp'.
dependencyInsight - Displays the insight into a specific dependency in root project 'projectReports'.
api:dependencyInsight - Displays the insight into a specific dependency in project ':api'.
webapp:dependencyInsight - Displays the insight into a specific dependency in project ':webapp'.
help - Displays a help message.
api:help - Displays a help message.
webapp:help - Displays a help message.
model - Displays the configuration model of root project 'projectReports'. [incubating]
api:model - Displays the configuration model of project ':api'. [incubating]
webapp:model - Displays the configuration model of project ':webapp'. [incubating]
projects - Displays the sub-projects of root project 'projectReports'.
api:projects - Displays the sub-projects of project ':api'.
webapp:projects - Displays the sub-projects of project ':webapp'.
properties - Displays the properties of root project 'projectReports'.
api:properties - Displays the properties of project ':api'.
webapp:properties - Displays the properties of project ':webapp'.
tasks - Displays the tasks runnable from root project 'projectReports' 
   (some of the displayed tasks may belong to subprojects).
api:tasks - Displays the tasks runnable from project ':api'.
webapp:tasks - Displays the tasks runnable from project ':webapp'.

यहाँ तालिका के विभिन्न विकल्पों में आदेशों की कुछ सूची दी गई है।

अनु क्रमांक। आदेश विवरण
1 gradle –q help –task <कार्य नाम> एक विशिष्ट कार्य या कई कार्यों के बारे में उपयोग की जानकारी (जैसे पथ, प्रकार, विवरण, समूह) प्रदान करता है।
2 gradle –q निर्भरताएँ चयनित परियोजना की निर्भरता की एक सूची प्रदान करता है।
3 gradle -q api: निर्भरताएँ --configuration <कार्य नाम> कॉन्फ़िगरेशन से संबंधित सीमित निर्भरता की सूची प्रदान करता है।
4 gradle –q buildEnvironment स्क्रिप्ट की निर्भरता के निर्माण की सूची प्रदान करता है।
5 gradle –q dependencyInsight एक विशेष निर्भरता में एक अंतर्दृष्टि प्रदान करता है।
6 ग्रेडल गुण चयनित परियोजना के गुणों की सूची प्रदान करता है।