GitHub의 maven 저장소
개발자는 특별한 site-maven-plugin 플러그인이 있는 GitHub에 라이브러리를 업로드할 수 있습니다 . 사용 예를 살펴보겠습니다.
<project>
<properties>
<github.global.server>github</github.global.server>
<github.maven-plugin>0.9</github.maven-plugin>
</properties>
<distributionManagement>
<repository>
<id>internal.repo</id>
<name>Temporary Staging Repository</name>
<url>file://${project.build.directory}/mvn-repo</url>
</repository>
</distributionManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
<configuration>
<altDeploymentRepository>
internal.repo::default::file://${project.build.directory}/mvn-repo
</altDeploymentRepository>
</configuration>
</plugin>
<plugin>
<groupId>com.github.github</groupId>
<artifactId>site-maven-plugin</artifactId>
<version>${github.maven-plugin}</version>
<configuration>
<message>Maven artifacts for ${project.version}</message>
<noJekyll>true</noJekyll>
<outputDirectory>${project.build.directory}/mvn-repo</outputDirectory>
<branch>refs/heads/mvn-repo</branch>
<includes>**/*</includes>
<repositoryName>SuperLibrary</repositoryName>
<repositoryOwner>codegymu-student</repositoryOwner>
</configuration>
<executions>
<execution>
<goals>
<goal>site</goal>
</goals>
<phase>deploy</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
여기에 쓰여진 것을 보자.
임시 로컬 리포지토리 생성은 파란색으로 강조 표시됩니다. 기술적으로는 폴더일 뿐이지만 별도의 저장소로 취급하려면 Maven이 필요합니다.
maven-deploy-plugin 플러그인의 시작을 빨간색으로 강조 표시했으며 여기서 컴파일된 라이브러리를 이 임시 저장소에 배치해야 한다고 표시했습니다.
마지막으로 site-maven-plugin 플러그인이 녹색으로 강조 표시되어 저장소에서 모든 파일을 가져와 GitHub에 커밋해야 합니다. 여기에 약간의 설명이 필요합니다. 모든 매개변수는 채울 대상과 채울 위치의 두 그룹으로 나뉩니다.
작성 내용:- outputDirectory - 커밋할 파일을 가져올 디렉터리
- 포함 - 커밋할 파일의 마스크를 설정합니다.
- repositoryOwner - GitHub의 저장소 소유자 이름
- repositoryName - 저장소 이름
- branch - 커밋할 GitHub의 리포지토리 분기를 설정합니다.
- message - 커밋 시 추가될 메시지
또한 Maven setting.xml 에서 리포지토리에 대한 로그인 및 암호를 지정해야 합니다 .
<settings>
<servers>
<server>
<id>github</id>
<username>[username]</username>
<password>[password]</password>
</server>
</servers>
</settings>
GitHub 리포지토리의 라이브러리를 다른 프로젝트에 연결(사용)하려면 pom.xml 에 이 리포지토리를 지정해야 합니다 .
<repositories>
<repository>
<id>[name-project]-mvn-repo</id>
<url>https://raw.github.com/[username]/[name-project]/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
그런 다음 Maven은 라이브러리를 가져올 위치를 이해합니다.
- [name-project] 는 프로젝트의 이름입니다. 이 경우에는 SuperLibrary입니다.
- [username] 은 GitHub의 로그인이며, 이 예에서는 codegym-user입니다.
어셈블리를 Docker 이미지로 압축
우리는 조립 결과 프로젝트를 Maven 리포지토리 또는 도커 스토리지에 배치할 수 있는 새로운 시대에 살고 있습니다.
Maven과 Docker를 친구로 만들려면 docker-maven-plugin 플러그인이 필요합니다 . 복잡하지 않음:
<build>
<plugins>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.10</version>
<configuration>
<dockerDirectory>${project.basedir}</dockerDirectory>
<imageName>codegym/${project.artifactId}</imageName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
파란색으로 강조 표시된 부분은 빌드의 패키지 단계에 목표 bulid를 추가한 지점입니다. mvn docker:build 명령 으로 호출할 수 있습니다 .
dockerDirectory 태그는 Dockerfile이 있는 폴더를 지정합니다. 그리고 imageName 태그를 사용하여 이미지의 이름을 설정합니다 .
프로젝트가 jar 파일로 패키징된 경우 docker 파일은 다음과 같이 표시됩니다.
FROM java:11
EXPOSE 8080
ADD /target/demo.jar demo.jar
ENTRYPOINT ["java","-jar","demo.jar"]
웹 애플리케이션을 패키징하는 경우 Tomcat을 추가해야 할 수 있습니다.
FROM tomcat8
ADD sample.war ${CATALINA_HOME}/webapps/ROOT.war
CMD ${CATALINA_HOME}/bin/catalina.sh run
GO TO FULL VERSION