2021-03-19-maven-settings

๋“ค์–ด๊ฐ€๋ฉฐ

  • Maven์—์„œ ์ž์ฃผ ๋งˆ์ฃผ์น˜๋Š” ์„ค์ • ํŒŒ์ผ์ธ settings.xml์ด ์žˆ์Šต๋‹ˆ๋‹ค.
  • ๋ฌด์Šจ ์—ญํ• ์„ ๊ฐ€์ง€๊ณ  ์žˆ๋Š”์ง€ ์–ด๋–ป๊ฒŒ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์ •๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

settings.xml์€ ๋ฌด์Šจ ์„ค์ •์„ ์œ„ํ•œ ํŒŒ์ผ์ผ๊นŒ?

  • Maven ์‹คํ–‰์— ํ•„์š”ํ•œ ์„ค์ •๋“ค์„ ์ •์˜ํ•˜๋Š” ํŒŒ์ผ์ž…๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿผ ์™œ pom.xml์— ์•ˆ ๋„ฃ๊ณ  settings.xml์„ ๋”ฐ๋กœ ๋งŒ๋“ค์—ˆ์„๊นŒ?
    • ํŠน์ • ํ”„๋กœ์ ํŠธ์— ์ข…์†๋˜๋Š” ์ •๋ณด๊ฐ€ ์•„๋‹ˆ๋‹ค.

settings.xml์€ ์–ด๋””๊ณณ์— ์žˆ์„๊นŒ?

  • ${user.home}/.m2/settings.xml
    • default path
  • ${maven.home}/conf/settings.xml
  • ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด custom settings.xml์„ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    • mvn package -s ./setting/settings.xml

settings.xml์€ ๋ฌด์Šจ ์ •๋ณด๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์„๊นŒ?

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
    <localRepository/>
    <interactiveMode/>
    <offline/>
    <pluginGroups/>
    <servers/>
    <mirrors/>
    <proxies/>
    <profiles/>
    <activeProfiles/>
</settings>

Simple Values

  • localRepository
    • maven ๋กœ์ปฌ ์ €์žฅ์†Œ ์œ„์น˜
  • interactiveMode
    • ์‚ฌ์šฉ์ž์˜ input์— ์›€์ง์žˆ๋Š” ๋ชจ๋“œ๋กœ ๋ณ€๊ฒฝ
    • default true
  • offline
    • remote ์ €์žฅ์†Œ์— ์—ฐ๊ฒฐํ•˜์ง€ ์•Š๊ณ  ๋นŒ๋“œ๋ฅผ ํ•˜๊ธฐ ์œ„ํ•œ ์˜ต์…˜
    • default false
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>${user.home}/.m2/repository</localRepository>
  <interactiveMode>true</interactiveMode>
  <offline>false</offline>
  ...
</settings>

Plugin Groups

  • pom.xml์— groupId๊ฐ€ ์„ค์ •๋˜์–ด ์žˆ์ง€ ์•Š์„ ๋•Œ ์„ ์–ธ๋œ GroupId๋กœ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ํƒ์ƒ‰
    • plugin์— groupId๋ฅผ ํ‘œ์‹œํ–ˆ๋‹ค๋ฉด ์•„๋ฌด ๊ธฐ๋Šฅ๋„ ํ•˜์ง€ ์•Š์Œ.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <pluginGroups>
    <pluginGroup>org.eclipse.jetty</pluginGroup>
  </pluginGroups>
  ...
</settings>

Servers

  • ์ €์žฅ์†Œ ์„œ๋ฒ„์— ๊ด€๋ จ๋œ ์„ค์ •
    • ์ €์žฅ์†Œ(nexus)์˜ ์ธ์ฆํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <servers>
    <server>
      <id>server001</id>
      <username>my_login</username>
      <password>my_password</password>
      <privateKey>${user.home}/.ssh/id_dsa</privateKey>
      <passphrase>some_passphrase</passphrase>
      <filePermissions>664</filePermissions>
      <directoryPermissions>775</directoryPermissions>
      <configuration></configuration>
    </server>
  </servers>
  ...
</settings>

Mirros

  • ์ €์žฅ์†Œ์— ๋Œ€ํ•œ ๋‹ค์šด๋กœ๋“œ mirror๋ฅผ ์„ค์ •ํ•˜๋Š” ์†์„ฑ

  • ์™œ Mirror๊ฐ€ ํ•„์š”ํ• ๊นŒ?

  • ์•„๋ž˜์˜ ์˜ˆ๋Š” https://repo.maven.apache.org/maven2/๋กœ ๋“ฑ๋ก๋œ plugin๋“ค์„ planetmirror.com์œผ๋กœ mirrorํ•ฉ๋‹ˆ๋‹ค.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <mirror>
      <id>planetmirror.com</id>
      <name>PlanetMirror Australia</name>
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>

Proxies

  • ๋ฐฉํ™”๋ฒฝ์ด๋‚˜ SSL ์ด์Šˆ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Proxy ์„ค์ •์„ ํ•ฉ๋‹ˆ๋‹ค.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <proxies>
    <proxy>
      <id>myproxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.somewhere.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts> // ํ•ด๋‹น ๋„๋ฉ”์ธ์€ Proxy ์ ์šฉ์ด ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
    </proxy>
  </proxies>
  ...
</settings>

Profiles

  • JDK ๋ฒ„์ ผ, OS์— ๋งž๊ฒŒ ๋นŒ๋“œ ๊ตฌ์„ฑ์„ ๋‹ค๋ฅด๊ฒŒ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <profiles>
    <profile>
      <id>test</id>
      <activation>
        <activeByDefault>false</activeByDefault>
        <jdk>1.5</jdk>
        <os>
          <name>Windows XP</name>
          <family>Windows</family>
          <arch>x86</arch>
          <version>5.1.2600</version>
        </os>
        <property>
          <name>mavenVersion</name>
          <value>2.0.3</value>
        </property>
        <file>
          <exists>${basedir}/file2.properties</exists>
          <missing>${basedir}/file1.properties</missing>
        </file>
      </activation>
      ...
    </profile>
  </profiles>
  ...
</settings>

Active Profiles

  • ์œ„์— ์„ ์–ธํ•œ Profile์„ ์ •์˜ํ•˜๋ฉด ํ•ด๋‹น Profile๋กœ ๋นŒ๋“œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
  • ์—ฌ๋Ÿฌ Profile์„ ์„ ์–ธํ•˜๋ฉด ์ˆœ์„œ๋Œ€๋กœ ๋นŒ๋“œ๊ฐ€ ๋ฉ๋‹ˆ๋‹ค.
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <activeProfiles>
    <activeProfile>env-test</activeProfile>
  </activeProfiles>
</settings>

Reference