Skip to content

Instantly share code, notes, and snippets.

@rolroralra
Last active October 30, 2021 07:38
Show Gist options
  • Save rolroralra/a9ef09e2724c84c499aa5cdff89c5b6d to your computer and use it in GitHub Desktop.
Save rolroralra/a9ef09e2724c84c499aa5cdff89c5b6d to your computer and use it in GitHub Desktop.
Maven

Settings.xml

Details

<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
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">

  <!-- <localRepository>${user.home}/.m2/repository</localRepository> -->

  <profiles>
    <profile>
      <id>rolroralra</id>
      <repositories>
        <repository>
           <id>central</id>
           <url>https://repo1.maven.org/maven2</url>
           <snapshots>
               <enabled>false</enabled>
           </snapshots>
           <releases>
               <enabled>true</enabled>
           </releases>
       </repository>

        <repository>
          <id>nexus-release</id>
          <name>nexus-release</name>
          <url>https://nexus.rolroralra.com</url>
          <snapshots>
              <enabled>false</enabled>
          </snapshots>
          <releases>
              <enabled>true</enabled>
          </releases>
        </repository>
        <repository>
          <id>nexus-snapshot</id>
          <name>nexus-snapshot</name>
          <url>https://nexus.rolroralra.com</url>
          <snapshots>
              <enabled>true</enabled>
          </snapshots>
          <releases>
              <enabled>false</enabled>
          </releases>
        </repository>
      </repositories>

      <!-- <proxies>
        <proxy>
          <id>http-proxy</id>
          <active>true</active>
          <protocol>http</protocol>
          <host>proxy.example.com</host>
          <port>8080</port>
          <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
        </proxy>
        <proxy>
          <id>https-proxy</id>
          <active>true</active>
          <protocol>https</protocol>
          <host>proxy.example.com</host>
          <port>8080</port>
          <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
        </proxy>
      </proxies> -->
    </profile>
  </profiles>

  <servers>
    <server>
      <id>nexus-release</id>
      <username>user-id</username>
      <password>password/password>
    </server>
    <server>
      <id>nexus-snapshot</id>
      <username>user-id</username>
      <password>password</password>
    </server>
  </servers>

  <!-- <mirrors>
    <mirror>
      <id>nexus-mirror</id>
      <name>nexus-mirror</name>
      <url>https://nexus.rolroralra.com/repository/maven-central/</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors> -->

  <activeProfiles>
    <activeProfile>rolroralra</activeProfile>
  </activeProfiles>

</settings>


pom.xml

Details

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>gof</groupId>
	<artifactId>gof</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<sourceDirectory>src</sourceDirectory>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.5.1</version>
				<configuration>
					<source>1.8</source>
					<target>1.8</target>
				</configuration>
			</plugin>
     </plugins>
	</build>


	<dependencies>
		<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
		<dependency>
			<groupId>org.projectlombok</groupId>
			<artifactId>lombok</artifactId>
			<version>1.18.22</version>
			<scope>provided</scope>
		</dependency>
	</dependencies>
</project>


Deploy custom registry setting in pom.xml

Details

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example.rolroralra</groupId>
    <artifactId>okhttp</artifactId>
    <version>1.0-SNAPSHOT</version>

    <distributionManagement>
        <repository>
            <uniqueVersion>false</uniqueVersion>
            <id>nexus-release</id>
            <name>nexus-release</name>
            <url>https://nexus.rolroralra.com/repository/maven-releases/</url>
            <layout>default</layout>
        </repository>
        <snapshotRepository>
            <uniqueVersion>true</uniqueVersion>
            <id>nexus-snapshot</id>
            <name>nexus-snapshot</name>
            <url>https://nexus.rolroralra.com/repository/maven-snapshots/</url>
            <layout>legacy</layout>
        </snapshotRepository>
    </distributionManagement>
  
    ...
</project>


settings-security.xml

http://kysepark.blogspot.com/2015/06/maven.html


Dependency Scope

Details

  • compile

기본 scope. 미입력시에도 기본 적용. 모든 상황에서 포함됨

  • provided

compile과 유사하게 모든 상황에서 수행된다.
하지만, 다른 외부 컨테이너에서 기본 제공되는 API인경우 provided로 지정 시 마지막 패키징할 때 포함되지 않음.
예를 들면 tomcat에서 기본적으로 servlet api를 제공하기 때문에 servlet api를 provided로 지정하면 패키징시 제외된다.

  • runtime

컴파일 시에는 불필요 실행시에 필요한 경우.
런타임 및 테스트 시 classpath에 추가 되지만, 컴파일시에는 추가 되지 않음.

  • test

테스트시에만 사용

  • system

provided와 유사. system의 특정 path를 참조하도록 지정. Maven의 central repository를 사용하지 않음

  • import

scope는 dependencyManagement 섹션에서 pom의 의존관계에 대해 사용

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment