Siv Gradle kom lawv muaj tej yaam num java?

Txheej txheem cej luam: Gradle yog ib suab yog ib qhov cuab tam uas siv lub ntsiab ntawm Apache ntsaum thiab Apache Maven lub tsev. Gradle yog xyuas los ntawm tus sau tej lus es tus me XML kev siv Apache ntsaum thiab Apache Maven. Gradle yog tsim los txhawb ntau yog ib qhov thaum uas puas loj heev thiab nws yuav lub tsho txoj hauj lwm kom tswj ntawm ntsaum los yog Maven.

Nyob rau cov tshooj no kuv yuav tham txog lub ntsiab ntawm Gradle ua yog ib ib qhov cuab tam lub tsev thiab qhia seb yuav ua li cas rau configure thiab ua ib tug qauv java yog ib qhov siv yam tshuaj no.

Taw qhia: Gradle yog ib tug tuam xoovtooj kaw cia pab muaj uas yuav siv tau los automate lub tuam tsev txoj, soj ntsuam, publishing, deploying, generating API documentations thiab lwm yam.

Nta: Gradle ua li uas sau nta:

  • Muaj declarative – Gradle muab declarative lus hais uas peb yuav tsum tau assembled as per peb xaiv. Qhov lus declarative yog extensible uas enables peb mus ntxiv rau wb cov lus tshiab los yog txhim khu cov uas twb muaj lawm ib. Cov ntsiab qhia muaj los ntawm kev them nyiaj yug convention rau Java, Groovy thiab lwm hom tshiab Java raws li yees.
  • Hais lus rau cov quav tshuaj raws li cov programming – Cov lus declarative yog saj zawg zog heev npaum li cas thiab enables Gradle los txhawb rau cov cai.
  • Cov muaj qauv – Gradle pub peb siv hom qauv tsim los peb muaj uas peb tsim muaj xyaum kom peb kev siv enables.
  • Scalability – Gradle muaj cov muaj peev xwm ua tau yooj yim teev ntawm ib qhov yooj yim xwb yog ib qhov muaj rau ib tug loj loj enterprise multiproject muaj. Nws enables cov incremental muaj thiab muaj peev xwm tackle cov teeb meem ntawv twg yog cov uas nquag loj enterprise muaj scripts muaj.
  • Kev them nyiaj yug multiproject – Gradle txhawb ntau yog ib qhov thaum. Nws enables peb kom muaj txoj kev sib raug zoo ntawm tej yaam num thaum ib multiproject tsim ib puag ncig. Nws kuj txhawb thaum ib nrab. Peb yuav tsim ib zaug xwb subproject tawm hauv koj daim ntawv thov enterprise. Thaum tus hluas subproject lub tsev, gradle yuav saib xyuas thiab qhov subprojects yog lub subproject said muaj quav rau lwm subprojects.
  • Kev tswj hauv kev quav dej caws – Gradle muaj ntau txoj kev uas tswj sab hauv thiab raws li lwm cov dependencies. Nws muaj kev txhawb rau txhua hom quav tswj txij transitive quav tswj coj mus saib tej thaj chaw deb maven los yog muaj lwm yam repository thiab lawv lub zos txawm cia.
  • Cuab tam kev koom ua ke – Gradle tau yooj yim import cov ntsaum yog ib qhov thiab nws lub hom phaj thiab converts rau hom Gradle kev pab raws qib ntawm runtime. Gradle tseem muab conversion mechanism mus siv tau cov ntaub ntawv maven pom.xml rau hauv tsab ntawv Gradle.
  • Migration – Yooj yim Gradle adapts muaj qauv. Peb yuav yooj yim tsim muaj Gradle rau cov ceg ntau lawm tib.
  • Kev them nyiaj yug groovy – Gradle scripts sau nyob rau hauv Groovy thiab tsis XML li.

Gradle Architecture: Daim duab hauv qab no qhia tias lub Cheebtsam architecture ntawm Gradle tuam tuam.

Gradle Architecture

Gradle Architecture

Plahaum thiab siv:

Gradle los txog hauv ib lub nras zauv teb thiab yuav tsum downloaded ntawm http://www.gradle.org/downloads. Rau hauv website, koj yuav nrhiav tau peb downloadable ntaub ntawv –

  • gradle-<VERSION>-All.Zip – No lub nras muaj tag nrho Cheebtsam xws li binaries, tau qhov twg los thiab lwm cov ntaub ntawv.
  • gradle-<VERSION>-bin.Zip – No lub nras muaj tus binaries xwb.
  • gradle-<VERSION>-src.Zip – No lub nras muaj tsuas rau ntawm qhov ntaub ntawv.

Ua ib tug beginner, Kuv lub tswv yim no mus download tau lub gradle-<VERSION>-cov ntaub ntawv All.Zip. Unzip no nras ntawm koj UNIX thiab append ntawv tais ceev tseg rau hauv tus mus rau txoj kev.

Siv cov kauj ruam nram no kom tiav tus plahaum:

Ua ib tug pov nruab JDK 1.5 lossis siab dua ntawd. Groovy lub tsev qiv ntawv los rau ntawm lub nras Gradle ces tsis tas nyias nruab Groovy.

  • Download tau Gradle tis ntawm http://www.gradle.org/downloads
  • Gradle tis los ua ib tug zauv teb ntaub ntawv. Unpack tus tis.
  • Ntxiv GRADLE_HOME los rau hauv koj kev nyob kuj sib txawv thiab. Kom txaus khiav Gradle taw tes no yog.
  • Khiav Gradle ntawm qhov hais kom ua gradle. Kos tus plahaum Gradle siv gradle - v hais kom ua. Nws yuav tso saib Gradle version thiab lwm yam lus.

Sim cov plahaum, cias ntaus ' gradle’ rau koj davhlau ya nyob twg, koj yuav tsum tau saib cov nram qab no tso zis:

Listing1: Qauv uas qhia tus plahaum los soj ntsuam

[Chaws]

: pab

Zoo siab Tostxais Gradle <Version>.

Khiav ib yuav muaj, khiav gradle <neeg ua hauj lwm>…

Pom ib daim ntawv uas muaj cov paub tab, khiav gradle paub tab

Pom ib daim ntawv teev kev command-line, khiav gradle –pab

MUAJ ZOO

Sij hawm: 3.135 secs

[/Chaws]

Thaum peb tau nrog tus plahaum, mus saib qhov no, peb ua ib tug qauv java yog ib qhov uas muaj hoob kawm java tej yam yooj yim li qis –

Listing2: Qauv uas qhia Java ntaub ntawv yooj yim

[Chaws]

pob com.Home.gradletest;

pej xeem hoob MyGradleSample {

pej xeem zoo li qub khoob lug ntsiab( Txoj hlua[] args ) {

Tsim.tawm.println( ” Hello rau txhua tus . ” );

Tsim.tawm.println( ” Yog hais tias koj yuav saib tau cov zis no , nws txhais tau hais tias koj tus plahaum gradle yog vam meej ! ” );

}

}

[/Chaws]

Thiaj li khiav gradle koj yuav tsum muaj ib tug 'build.gradle'. Yog hais tias koj tsis muaj cov ntaub ntawv no, tseem koj nrhiav tau yam kev pab raws qib uas pab rau peb tes num. Cias yam hauv qab no –

Listing3: Qauv uas qhia muaj cov paub tab

[Chaws]

gradle cov paub tab

[/Chaws]

Koj yuav tsum tau saib cov zis hauv qab no –

[Chaws]

:paub tab
== Cov paub tab ntawm cov hauv paus hniav yog ib qhov runnable
== Tsim teeb paub tab
setupBuild – Initializes muaj Gradle tshiab. [ib]
wrapper – Generates Gradle wrapper ntaub ntawv. [ib]
== Pab kom paub tab
dependencies – Qhia txog tag nrho dependencies tus me nyob rau hauv lub hauv paus yog ib qhov 'gradletest'.
dependencyInsight – Qhia txog txoj kev pom rau ib kev quav tshuaj nyob rau hauv lub hauv paus yog ib qhov 'gradletest'.
pab – Qhia txog cov lus pab
tej yaam num – Qhia lub ncua tej yaam num ntawm lub hauv paus yog ib qhov 'gradletest'.
khoom – Qhia txog lub zog ntawm cov hauv paus hniav yog ib qhov 'gradletest'.
paub tab – Qhia txog cov kev pab raws qib runnable los ntawm hauv paus yog ib qhov 'gradletest'.

Saib cov luag hauj lwm thiab nthuav dav ntxiv, cav nrog –tag nrho.

MUAJ ZOO

Sij hawm: 2.667 secs

[/Chaws]

Mus start with peb tsim tau ib build.gradle yooj yim ntaub ntawv raws li hauv qab –

Listing4: Qauv qhia build.gradle tej ntaub ntawv

[Chaws]

thov plugin: ' java’

thov plugin: ' dab noj hnub’

// lossis::repositories[]

repositories {

mavenCentral()

}

// kawg::repositories[]

// lossis::hwj iav[]

hwj iav {

baseName = ' gradletest’

Version = ‘0.9’

}

// kawg::hwj iav[]

// lossis::dependencies[]

dependencies {

compile “joda-lub sij hawm:joda-lub sij hawm:2.2”

}

// kawg::dependencies[]

// lossis::wrapper[]

neeg ua hauj lwm wrapper(hom: Wrapper) {

gradleVersion = '<NTSIA VERSION OF GRADLE>’

}

// kawg::wrapper[]

[/Chaws]

Gradle ntawv saum toj no yog ib tug yooj yim heev. Tam sim no yog peb khiav lub ' ua hauj lwm gradle’ hais kom ua dua, peb pom tau ib daim ntawv teev kev paub tab muaj tsim peb tes num, tsim javadocs thiab lwm yam. Ntawm no peb mam li siv ib lub ' gradle muaj’ neeg ua hauj lwm ntau heev. Saib rau qhov hauj lwm no yog –

  • Compiling cov khawb hauv qhov chaws
  • Si laim qhov mus kawm
  • Assembling cov cai nyob rau hauv ib lub thawv los yog ib daim ntawv ua tsov ua rog.

Thaum ua hauj lwm muaj tseg, peb saib ' lawv muaj kev vam meej’ xov uas peb pom tau ntau ntxiv nyob rau hauv daim nplaub tshev muaj folders. Qhov sawv daws yuav tshaj li tsis yog –

  • Hoob – Qhov no muaj cov hoob kawm ntaub ntawv ntawm qhov kev tsim.
  • Fawb – Qhov no muaj cov ntaub ntawv generated los ntawm qhov muaj e.g. ntaub ntawv junit (yog muaj)
  • libs – Qhov no muaj lub qhov project assembled qiv (feem ntau yog thawv los yog rog ntaub ntawv).

Tam sim no peb mus nyob rau hauv tsab ntawv saum toj no

  • Thawj ob peb kab mentions tus plugins uas peb xav tau lub sij hawm muaj txheej txheem.
  • Qhov tom ntej no yog cov repositories. Qhov no yog qhov chaw uas peb muab rau lwm tus neeg qiv. Thaum tus me, peb yeej npaj rau lwm tus neeg qiv. Ntawm no peb siv lub joda sij hawm qiv version 2.2 ntawm cov pab pawg neeg lub sij hawm joda. Qhov no yog piav nyob rau hauv lub dependencies nplov. Muaj lwm yam tseem ceeb dependencies
    • providedCompile – Qhov no muaj xws li cov dependencies siv compiling peb tes num.
    • testCompile – Qhov no muaj xws li cov dependencies rau compiling thiab khiav cov raug tus mob no ntawm ib qhov project.
  • Nyob hauv lub xeem thaiv peb thov qhia lub npe ntawm peb cov thawv ntaub ntawv nrog rau nws cov version.

Txoj kev: Nyob rau cov tshooj no peb pom tias Gradle muaj muaj zog thiab yooj ywm kablus ua raws. Enterprise theem ntawm lwm yam uas muaj nws thiab tus thaum tseem daim forms. Peb cia xaus peb sib tham nyob rau lub cia nyias qhov nram qab no –

  • Gradle yog ib qho cuab tam qhib tau qhov twg los muaj.
  • Gradle combines taub ntsaum Apache thiab Maven.
  • Gradle tawm nrog rau ib daim ntawv teev cov nta raws li tau piav los saum no.
  • Gradle tsis yog yooj yim heev rau nruab thiab siv.
Tagged:
============================================= ============================================== Yuav zoo TechAlpine phau ntawv rau Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Txaus siab rau qhov blog? Tshaj tawm lus thov :)

Follow by Email
LinkedIn
LinkedIn
Share