Upgrade to Pro — share decks privately, control downloads, hide ads and more …

まだ間に合うMaven(再)入門 #jjug

C74faf8a5336f2898b08202e98211e06?s=47 yusuke
December 11, 2020

まだ間に合うMaven(再)入門 #jjug

2020年12月11日 開催 JJUGナイトセミナー「Maven / Gradle入門」のMavenパートです。
https://jjug.doorkeeper.jp/events/114832

動画はこちら:
https://youtu.be/R5gWwOwo4iQ

C74faf8a5336f2898b08202e98211e06?s=128

yusuke

December 11, 2020
Tweet

Transcript

  1. ࢁຊϢʔεέ!ZVTVLF ·ͩؒʹ߹͏.BWFO ࠶ ೖ໳ 

  2. ຊ೔࿩͢͜ͱ w +BWBͷϏϧυํࣜͷྺ࢙ w .BWFOͷجຊ w .BWFOϓϩδΣΫτͷ࡞੒ํ๏ w ґଘϥΠϒϥϦͷ௥Ճ w

    .BWFOʹΑΔϏϧυ w .BWFOͷ࠷৽৘ใ 
  3. ຊ೔࿩͞ͳ͍͜ͱ w ݸผͷ*%&ͷৄࡉͳར༻ํ๏ w $*πʔϧ΍ύοέʔδαʔϏε࿈ܞͱ͍ͬͨൃలతͳ.BWFOͷ࢖͍ํ 

  4. ϏϧυճΓͰσϕϩού͕ߦ͍͍ͨ͜ͱ w ίϯύΠϧ w ςετ w ύοέʔδ KBSXBSFBSEPDLFSΠϝʔδ࡞੒  w

    ੒Ռ෺Λڞ༗ ଞͷσϕϩούɺ$*؀ڥɺύοέʔδϦϙδτϦ 
  5. +BWBͷϏϧυํࣜͷྺ࢙ 

  6. +BWBͷϏϧυํࣜͷྺ࢙ खಈͰίϚϯυϥΠϯϏϧυ w ຖճख࡞ۀ w ཤྺ͚͕ͩཔΓ w ଞͷਓ͕࠶ݱग़དྷͳ͍ 

  7. +BWBͷϏϧυํࣜͷྺ࢙ όονϑΝΠϧ CBU ɺγΣϧεΫϦϓτ TI w ϏϧυεΫϦϓτΛڞ༗Ͱ͖Δ w ϓϥοτϑΥʔϜʹґଘ͢Δ 

  8. +BWBͷϏϧυํࣜͷྺ࢙ *%&ͰϏϧυ DMBTTQBUI w *%&ʹґଘ͢Δ w $*αʔόͰϏϧυ͕ͮ͠Β͍ 

  9. +BWBͷϏϧυํࣜͷྺ࢙ "OU w YNMϑΝΠϧͰϏϧυΛఆٛ w ๛෋ͳϓϥάΠϯ  IUUQTBOUBQBDIFPSH

  10. աڈͷϏϧυํࣜͷ໰୊఺ w ϏϧυͰ͖Δ؀ڥ͕ݶఆ͞ΕΔ 04ɺ*%&ͳͲ  w खଓ͖ܕͰεΫϦϓτͷهड़ྔ͕ଟ͘ɺϝϯςφϯε͕೉͍͠ w σΟϨΫτϦߏ଄͕ϓϩδΣΫτຖʹ·ͪ·ͪ TSDTPVSDFσΟϨΫτϦʁMJCMJCTσΟϨΫτϦʁ

    w ιʔείʔυͱҰॹʹϥΠϒϥϦΛ7$4ʹอ؅͕ͪ͠ ग़ॴɺόʔδϣϯෆ໌ͷKBSϑΝΠϧ 
  11. .BWFO(SBEMFΛ࢖͏ͱ w ΫϩεϓϥοτϑΥʔϜͰϏϧυՄೳ w ଟ͕͘σϑΥϧτͰܾ·ΔɺએݴతʹϏϧυΛఆٛՄೳ w ๛෋ͳϓϥάΠϯ w ʮґଘʯΛએݴ͢Ε͹ϥΠϒϥϦΛࣗಈతʹऔಘ 

  12. .BWFO(SBEMFΛ࢖͏ͱ w ΫϩεϓϥοτϑΥʔϜͰϏϧυՄೳ w ଟ͕͘σϑΥϧτͰܾ·ΔɺએݴతʹϏϧυΛఆٛՄೳ w ๛෋ͳϓϥάΠϯ w ʮґଘʯΛએݴ͢Ε͹ϥΠϒϥϦΛࣗಈతʹऔಘ 

    21ੈل͸Maven͔GradleΛ࢖͍·͠ΐ͏
  13. .BWFOͷجຊ 

  14. .BWFOͱ͸ w ΫϩεϓϥοτϑΥʔϜͷ+BWBϏϧυπʔϧ w 

  15. .BWFOϓϩδΣΫτͷσΟϨΫτϦߏ੒ 

  16. .BWFOϓϩδΣΫτͷσΟϨΫτϦߏ੒  Javaιʔείʔυ Javaςετίʔυ Ϧιʔε (ϓϩύςΟϑΝΠϧͳͲ) ϏϧυఆٛϑΝΠϧ

  17. ͋ΕɺϥΠϒϥϦ͸Ͳ͜ʁ MJCσΟϨΫτϦ MJCTσΟϨΫτϦʁ 

  18. ϥΠϒϥϦ͸ϓϩδΣΫτσΟϨΫτϦʹஔ͔ͳ͍ w ར༻͢Δ ґଘ͢Δ ϥΠϒϥϦ͸QPNYNMʹهࡌ͢Δ͚ͩ 

  19. .BWFOϓϩδΣΫτʹ͓͚Δґଘ ϓϩδΣΫτ͕࢖͏ ґଘ͢Δ ϥΠϒϥϦΛࢦఆ w (SPVQ*EPSHKVOJUKVQJUFSͳͲ w "SUJGBDU*EKVOJUKVQJUFSBQJͳͲ w 7FSTJPOͳͲ

    
  20. .BWFOηϯτϥϧϦϙδτϦ w +BWBͷσϑΝΫτελϯμʔυϦϙδτϦ IUUQTSFQPNBWFOPSHNBWFO w ϝδϟʔͳϥΠϒϥϦ͕΄΅ἧ͍ͬͯΔ IUUQTSFQPNBWFOPSHNBWFOPSHKVOJUKVQJUFSKVOJUKVQJUFS IUUQTSFQPNBWFOPSHNBWFOMPHKMPHK IUUQTSFQPNBWFOPSHNBWFOPSHUXJUUFSKUXJUUFSKDPSF w

    ηϯτϥϧϦϙδτϦҎ֎΋ࢦఆՄೳ 
  21. .BWFOϓϩδΣΫτͷϥΠϒϥϦ w ϗʔϜσΟϨΫτϦNSFQPTJUPSZҎԼʹอ؅ w μ΢ϯϩʔυͨ͠ϥΠϒϥϦΛΩϟογϡ w 7$4ʹϥΠϒϥϦͷίϛοτෆཁ w QPNYNMͰʮґଘ EFQFOEFODZ

    ʯΛࢦఆ 
  22. .BWFOͷΠϯετʔϧํ๏  brew install mv n sdk install maven 3.6.

    3
  23. .BWFOͷΠϯετʔϧํ๏ wεςοϓ wεςοϓ wεςοϓ 

  24. .BWFOͷΠϯετʔϧํ๏ wεςοϓ޷Έͷ*%&ΛΠϯετʔϧ͢Δ wεςοϓ wεςοϓ 

  25. .BWFOͷΠϯετʔϧํ๏ wεςοϓ޷Έͷ*%&ΛΠϯετʔϧ͢Δ wεςοϓऴΘΓ wεςοϓ 

  26. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ 

  27. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ ίϚϯυϥΠϯ͔Β  mvn archetype:generate \ -DgroupId=com.samuraism.app \ -DartifactId=my-app \

    -DarchetypeArtifactId=maven-archetype-quickstart \ -DarchetypeVersion=RELEASE \ -DinteractiveMode=false BSDIFUZQF"SUJGBDUϓϩδΣΫτςϯϓϨʔτ %BSDIFUZQF"SUJGBDU*E
  28. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ &DMJQTF͔Β  

  29. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ &DMJQTF͔Β  

  30. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ *OUFMMJ+*%&"͔Β 

  31. .BWFOϓϩδΣΫτͷ࡞੒ํ๏ /FU#FBOT͔Β 

  32. ґଘϥΠϒϥϦͷ௥Ճ 

  33. ґଘϥΠϒϥϦͷ௥Ճ QPNYNM͔Β w EFQFOEFODJFTཁૉԼʹEFQFOEFODZཁૉͰࢦఆ 

  34. ґଘϥΠϒϥϦͷ௥Ճ *%&͔Β *OUFMMJ+*%&"/FU#FBOT w ࢖͍͍ͨγϯϘϧ໊Λॻ͍ͯ"MU &OUFS 

  35. ґଘϥΠϒϥϦͷ௥Ճ *%&͔Β &DMJQTF w QPNYNMΛӈΫϦοΫɺ"EE%FQFOEFODZ 

  36. ґଘϥΠϒϥϦͷείʔϓ w σϑΥϧτ͸DPNQJMF w ςετέʔεͰ͔͠࢖Θͳ͍΋ͷ͸TDPQFUFTUTDPQF w ΞϓϦέʔγϣϯαʔό౳Ͱఏڙ͞ΕΔ΋ͷ͸TDPQFQSPWJEFETDPQF 

  37. ϥΠϒϥϦͷݕࡧ IUUQTTFBSDINBWFOPSH 

  38. .BWFOʹΑΔϏϧυ 

  39. .BWFOʹΑΔίϯύΠϧ ίϚϯυϥΠϯ͔Β  % mvn compile

  40. .BWFOʹΑΔίϯύΠϧ *%&͔Β 

  41. NWODPNQJMFͰߦΘΕΔओͳ͜ͱ  ґଘϥΠϒϥϦΛ ඞཁʹԠͯ͡ μ΢ϯϩʔυ  NBJO಺ͷKBWBΛίϯύΠϧͯ͠UBSHFUDMBTTFTʹDMBTTϑΝΠϧΛੜ੒  NBJOSFTPVSDFTσΟϨΫτϦҎԼͷϑΝΠϧΛUBSHFUDMBTTFTʹίϐʔ 

  42. .BWFOʹΑΔςετ 

  43. .BWFOʹΑΔςετ ίϚϯυϥΠϯ͔Β  % mvn test *%&͔Β

  44. NWOUFTUͰߦΘΕΔओͳ͜ͱ ίϚϯυϥΠϯ͔Β  NWODPNQJMF  UFTU಺ͷKBWBΛίϯύΠϧͯ͠UBSHFUUFTUDMBTTFTʹDMBTTϑΝΠϧΛੜ੒  UFTUSFTPVSDFTҎԼͷϑΝΠϧΛUBSHFUUFTUDMBTTFTʹίϐʔ  ϓϩδΣΫτ಺ͷςετέʔεΛ࣮ߦ

    
  45. +6OJUΛ࢖͍ͬͯΔ৔߹ σϑΥϧτͰ͸ςετ͕࣮ߦ͞Εͳ͍ ೥݄೔ݱࡏ  ࠷৽TVSF f i SFϏϧυϓϥάΠϯΛ໌ࣔతʹࢦఆ  <build>

    <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.2</version> </plugin> </plugins> </build>
  46. .BWFOʹΑΔύοέʔδ 

  47. NWOQBDLBHFͰߦΘΕΔओͳ͜ͱ ίϚϯυϥΠϯ͔Β  NWODPNQJMF  NWOUFTU  ςετ͕શͯ੒ޭ͢Ε͹ UBSHFUʹKBSϑΝΠϧΛ࡞੒ 

  48. .BWFOʹΑΔΠϯετʔϧ 

  49. NWOJOTUBMMͰߦΘΕΔओͳ͜ͱ ίϚϯυϥΠϯ͔Β  NWODPNQJMF  NWOUFTU  ςετ͕શͯ੒ޭ͢Ε͹ NWOQBDLBHF 

    ϗʔϜNSFQPTJUPSZσΟϨΫτϦʹ੒Ռ෺Λίϐʔ 
  50. ஌͓ͬͯ͘ͱศར w NWODMFBO ੜ੒͞ΕͨϑΝΠϧΛશͯ࡟আ͢Δ w %NBWFOUFTUTLJQUSVF ςετΛεΩοϓ͢Δ w NWOEFQFOEFODZUSFF ґଘϥΠϒϥϦΛҰཡදࣔ

    w NWOEFQMPZ σϓϩΠ ੒Ռ෺Λڞ༗  % mvn -Dmaven.test.skip=true install
  51. ༷ʑͳύοέʔδϦϙδτϦʹσϓϩΠՄೳ  +FU#SBJOT4QBDF (JU)VC +'SPH

  52. ͲͷόʔδϣϯΛ࢖͏΂͖ʁ w +BWBҎ߱.BWFO w +BWB.BWFO w +BWB.BWFO w +BWB·ͨ͸ͦΕҎલ.BWFOԽͱಉ࣌ʹ+BWB ·ͨ͸+BWB

    ΁Ҏ߱  ࢀߟ.BWFO3FMFBTFT)JTUPSZ IUUQTNBWFOBQBDIFPSHEPDTIJTUPSZIUNM
  53. .BWFOͰԿ͕มΘΔʁ w ϚϧνϞδϡʔϧϏϧυͷվળ w SFTVNFͰࣦഊͨ͠Ϟδϡʔϧ͔ΒϏϧυ w NWOKFUUZSVOͳͲͰඞཁͳϞδϡʔϧΛϏϧυͯ͘͠ΕΔ w ਌ϞδϡʔϧΛࢦఆ͢Ε͹શࢠϞδϡʔϧΛϏϧυ NWOQMFYUFOTJPOTHSQDDPEFHFO

    FYUFOTJPOTHSQDEFQMPZNFOUʜʜˠNWOQMFYUFOTJPOTHSQD w .BWFO8SBQQFS NWOX ͕ඪ४ʹ w ࣗಈόʔδϣχϯά ਌Ϟδϡʔϧͷόʔδϣϯ͕ࢦఆෆཁʹ  ࢀߟ8IBUT/FXJO.BWFO IUUQTNBBSUFONVMEFSTJUXIBUTOFXJONBWFO
  54. .BWFOͷ։ൃঢ়گΛ஌Δ  IUUQTJTTVFTBQBDIFPSHKJSBQSPKFDUT./(WFSTJPOT

  55. ·ͱΊ w TIɺCBUɺCVJMEYNM "OU ͰϏϧυ͍ͯ͠Δ৔߹ɺࠓ೔͔Β࢝ΊΑ͏ w .BWFO (SBEMF  w

    ಋೖͨ͠Β௅ઓ͠Α͏ w $* w 5%% w ύοέʔδϦϙδτϦ