Maven发布war到私服
pom配置
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>http://172.16.20.103:8081/repository/maven-snapshots/</url>
</snapshotRepository>
<repository>
<id>releases</id>
<url>http://172.16.20.103:8081/repository/maven-releases/ </url>
</repository>
</distributionManagement>
如果是snapshots的,pom的版本号后面的snapshot必须是大写 SNAPSHOT,如下
<groupId>com.fsl</groupId>
<artifactId>lcp.hotfix</artifactId>
<version>2.0-SNAPSHOT</version>
<packaging>war</packaging>
settings文件配置
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
snapshots的版本为不稳定版本,可在不更改版本号的前提下,多次发布,私库会自动添加日期区分,同时使用方可配置为自动更新最新的snapshots(为了安全,maven组件默认关闭的,下面的配置二选一便可以)
项目pom.xml如下配置
<repositories>
<repository>
<id>nexus</id>
<name>ex</name>
<url>http://172.16.20.103:8081/repository/maven-public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
maven的settings.xml中配置
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<name>Nexus</name>
<url>http://172.16.20.103:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<name>Nexus</name>
<url>http://172.16.20.103:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
activeProfile一定要加,不然配置不生效。结构很简单,以profile的形式引入,pluginRepository节点可以不用引入,但是snapshots enabled必须设置为true。
参考 https://www.cnblogs.com/EasonJim/p/8318219.html
===================源码打包===================
使用maven-source-plugin插件将项目源码打包并发布到仓库中,在pom.xml配置文件中添加如下的配置代码:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
在intellij idea中执行maven install即可
执行 mvn install,maven会自动将source install到repository 。
执行 mvn deploy,maven会自动将source deploy到remote-repository 。
执行 mvn source:jar,单独打包源码。
============================war-作为overlays使用=======================
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses><!-- 把class打包jar作为附件 -->
</configuration>
</plugin>
引用war并合并overlays
<dependency>
<groupId>com.fsl</groupId>
<artifactId>lcp.hotfix</artifactId>
<classifier>classes</classifier>
<scope>provided</scope>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fsl</groupId>
<artifactId>lcp.wrapper</artifactId>
<type>war</type>
<version>2.0-RELEASE</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<attachClasses>true</attachClasses>
<overlays>
<!-- 合并 war包 -->
<overlay>
<groupId>com.fsl</groupId>
<artifactId>lcp.extension</artifactId>
</overlay>
<overlay>
<groupId>com.fsl</groupId>
<artifactId>lcp.hotfix</artifactId>
</overlay>
<overlay>
<groupId>com.fsl</groupId>
<artifactId>lcp.wrapper</artifactId>
<excludes>
<exclude>WEB-INF/lib/hap*</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>