nexus maven项目打包发布及引用
引用
1.pom文件中加入配置
<repositories>
<repository>
<id>maven-public</id>
<url>http://nexus3.luoyj.top/repository/maven-public/</url>
</repository>
</repositories>
2.加入依赖引用
<dependency>
<groupId>com.test</groupId>
<artifactId>test-common</artifactId>
<version>1.0.1</version>
</dependency>
打包发布
发布有两种方式,一种是手动,即登录到nexus后台手动上传。
另外一种,是通过maven插件自动上传发布。
1.编写java代码
2.pom文件中配置
<groupId>com.test</groupId>
<artifactId>test-common</artifactId>
<version>1.0.1</version>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<!--对于有多个第三方依赖的情况,第三方包 META-INF下会有一些相同的MINIFEST文件,maven-shade-plugin默认会使用追加而不是覆盖的方式处理它们。由于一些包重复引用,打包后的 META-INF 目录多出了一些 *.SF 等文件,执行jar包时,可能会抛出java.lang.SecurityException: Invalid signature file digest for Manifest main attributes异常。可以通过配置解决-->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<!--不在根目录生成打包时的缩减后的pom的xml临时文件-->
<createDependencyReducedPom>false</createDependencyReducedPom>
<transformers>
<!--对这个同名文件进行追加处理-->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<!--设置主函数-->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>cn.fht.test.test</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>maven-releases</id>
<url>http://nexus3.luoyj.top/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>maven-snapshots</id>
<url>http://nexus3.luoyj.top/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
3.maven配置文件settings.xml中配置nexus账号密码
<servers>
<server>
<id>maven-releases</id>
<username>admin</username>
<password>1234</password>
</server>
<server>
<id>maven-snapshots</id>
<username>admin</username>
<password>1234</password>
</server>
</servers>
4.点击deploy按钮或者执行命令
mvn clean deploy