目录
修改镜像源-settings.xml设置JDK版本-settings.xmlMaven命令安装jar包到本地仓库
Maven私服配置私服仓库-settings.xml配置私服仓库-pon.xml配置自动化部署配置认证信息-settings.xml配置部署-pom.xml
Maven插件spring-javaformat-maven-pluginscmdocker-maven-plugin
修改镜像源-settings.xml
<mirrors>
<mirror>
<id>alimaven
</id>
<name>aliyun maven
</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/
</url>
<mirrorOf>central
</mirrorOf>
</mirror>
</mirrors>
设置JDK版本-settings.xml
<profiles>
<profile>
<id>jdk-1.8
</id>
<activation>
<activeByDefault>true
</activeByDefault>
<jdk>1.8
</jdk>
</activation>
<properties>
<maven.compiler.source>1.8
</maven.compiler.source>
<maven.compiler.target>1.8
</maven.compiler.target>
<maven.compiler.compilerVersion>1.8
</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
Maven命令
安装jar包到本地仓库
mvn install:install-file -Dfile=demo-1.0.jar -DgroupId=com.example -DartifactId=demo -Dversion=1.0 -Dpackaging=jar
Maven私服
配置私服仓库-settings.xml
<mirror>
<id>nexus
</id>
<name>Nexus Repository
</name>
<url>http://127.0.0.1:8081/repository/maven-public/
</url>
<mirrorOf>*
</mirrorOf>
</mirror>
配置私服仓库-pon.xml
<repositories>
<repository>
<id>nexus
</id>
<name>Nexus Repository
</name>
<url>http://127.0.0.1:8081/repository/maven-public/
</url>
<snapshots>
<enabled>true
</enabled>
</snapshots>
<releases>
<enabled>true
</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus
</id>
<name>Nexus Plugin Repository
</name>
<url>http://127.0.0.1:8081/repository/maven-public/
</url>
<snapshots>
<enabled>true
</enabled>
</snapshots>
<releases>
<enabled>true
</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
配置自动化部署
配置认证信息-settings.xml
<server>
<id>nexus-releases
</id>
<username>admin
</username>
<password>admin123
</password>
</server>
<server>
<id>nexus-snapshots
</id>
<username>admin
</username>
<password>admin123
</password>
</server>
配置部署-pom.xml
<distributionManagement>
<repository>
<id>nexus-releases
</id>
<name>Nexus Release Repository
</name>
<url>http://127.0.0.1:8081/repository/maven-releases/
</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots
</id>
<name>Nexus Snapshot Repository
</name>
<url>http://127.0.0.1:8081/repository/maven-snapshots/
</url>
</snapshotRepository>
</distributionManagement>
Maven插件
spring-javaformat-maven-plugin
一个格式化代码的插件,能将代码格式化成Spring风格
<build>
<plugins>
<plugin>
<groupId>io.spring.javaformat
</groupId>
<artifactId>spring-javaformat-maven-plugin
</artifactId>
<version>0.0.22
</version>
<executions>
<execution>
<id>javaformat
</id>
<phase>package
</phase>
<goals>
<goal>apply
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
scm
版本管理插件(能自动打tag上传到git服务器,并把稳定版本少女工程到nexus)
pom
<distributionManagement>
<repository>
<id>nexus-releases
</id>
<url>http://182.92.122.135:8088/repository/maven-releases/
</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots
</id>
<url>http://182.92.122.135:8088/repository/maven-snapshots/
</url>
</snapshotRepository>
</distributionManagement>
<properties>
<java.version>1.8
</java.version>
<release.version>1.0.4.RELEASE
</release.version>
<snapshot.version>1.0.5-SNAPSHOT
</snapshot.version>
</properties>
<scm>
<connection>scm:git:https://gitee.com/gaoxiang6666/hello_demo.git
</connection>
<developerConnection>scm:git:https://gitee.com/gaoxiang6666/hello_demo.git
</developerConnection>
<url>https://gitee.com/gaoxiang6666/hello_demo.git
</url>
<tag>HEAD
</tag>
</scm>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot
</groupId>
<artifactId>spring-boot-maven-plugin
</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins
</groupId>
<artifactId>maven-release-plugin
</artifactId>
<version>2.5.3
</version>
<configuration>
<providerImplementations>
<git>jgit
</git>
</providerImplementations>
<username>gaoxiang6666
</username>
<password>12345678
</password>
<tagBase>${project.artifactId}-${project.version}
</tagBase>
<goals>-f pom.xml deploy
</goals>
<releaseLabel>${release.version}
</releaseLabel>
<releaseVersion>${release.version}
</releaseVersion>
<developmentVersion>${snapshot.version}
</developmentVersion>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.scm
</groupId>
<artifactId>maven-scm-provider-jgit
</artifactId>
<version>1.9.5
</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
命令
# 清理生成的文件 发布标签 上传发布(稳定版本)版本的jar包到Nexus私服
mvn release:clean release:prepare -DignoreSnapshots=true release:perform
# 上传快照版本到Nexus私服
mvn deploy
docker-maven-plugin
通过maven构建docker镜像,并使用harbor作为私有库
在maven的settings.xml中配置
<servers>
<server>
<id>182.92.122.135
</id>
<username>admin
</username>
<password>Harbor12345
</password>
<configuration>
<email>1528357474@qq.com
</email>
</configuration>
</server>
</servers>
<pluginGroups>
<pluginGroup>com.spotify
</pluginGroup>
</pluginGroups>
开启docker远程连接
vim /usr/lib/systemd/system/docker.service
修改[Service]下面的ExecStart
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
systemctl daemon-reload
service docker restart
项目的pom.xml
<properties>
<docker.registry.url>182.92.122.135
</docker.registry.url>
<docker.registry.host>http://${docker.registry.url}:2375
</docker.registry.host>
<docker.plugin.version>1.2.0
</docker.plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.spotify
</groupId>
<artifactId>docker-maven-plugin
</artifactId>
<version>${docker.plugin.version}
</version>
<configuration>
<imageName>${docker.registry.url}/library/${project.artifactId}:${project.version}
</imageName>
<dockerDirectory>${project.basedir}
</dockerDirectory>
<dockerHost>${docker.registry.host}
</dockerHost>
<resources>
<resource>
<targetPath>/
</targetPath>
<directory>${project.build.directory}
</directory>
<include>${project.build.finalName}.jar
</include>
</resource>
</resources>
<registryUrl>${docker.registry.url}
</registryUrl>
<serverId>${docker.registry.url}
</serverId>
<pushImage>true
</pushImage>
</configuration>
<executions>
<execution>
<id>docker-build-push
</id>
<phase>package
</phase>
<goals>
<goal>build
</goal>
<goal>push
</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[项目的根目录下加入Dockerfile]
FROM java:8
MAINTAINER 1528357474@qq.com
RUN mkdir -p /home/webapp
WORKDIR /home/webapp
ADD ./target/app.jar ./app.jar
EXPOSE 8080
CMD java -jar app.jar --spring.profiles.active=test