apache仓库地址
https://repository.apache.org/content/repositories/snapshots/
安装
下载maven安装包
修复配置文件 conf/settings.xml
设置阿里云镜像
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
配置maven环境变量
export M2_HOME=/usr/local/maven
export PATH=$PATH:$M2_HOME/bin
maven仓库
maven仓库
https://mvnrepository.com/
maven打包命令
mvn clean compile 编译
mvn clean package 打包
mvn clean install 安装至本地仓库
mvn clean deploy 安装至远程仓库
-DskipTests 不执行用例,会编译用例类
-Dmaven.test.skip=true 不执行用例,也不编译用例类
-P dev 执行哪个环境,和pom.xml中的profiles对应
-U 该参数能强制让Maven检查所有SNAPSHOT依赖更新,确保集成基于最新的状态,如果没有该参数,Maven默认以天为单位检查更新,而持续集成的频率应该比这高很多。
-e 如果构建出现异常,该参数能让Maven打印完整的stack trace,以方便分析错误原因。
-B 该参数表示让Maven使用批处理模式构建项目,能够避免一些需要人工参与交互而造成的挂起状态。
-Dpmd.skip=true 跳过PMD检查
-Dcheckstyle.skip=true 跳过checkstyle检查
打包命令示例
mvn clean compile package install deploy assembly:assembly -DskipTests=true
mvn clean compile package install assembly:assembly -DskipTests=true
打包参数作用 -pl -am -amd
-pl moduleName 仅打包所选择模块打包,多个模块以逗号分隔
-am 表示同时处理选定模块所依赖的模块
-amd 表示同时处理依赖选定模块的模块
mvn clean package -DskipTests=true -pl 模块名称 -am -amd
pom文件依赖范围
1.compile 默认范围,编译测试运行都有效
2.provided 在编译和测试时有效
3.runtime 在测试和运行时有效
4.test 只在测试时有效
5.system 在编译和测试时有效,与本机系统关联,可移植性差
maven发布到仓库
<distributionManagement>
<repository>
<id>releases</id>
<name>releases</name>
<url>http://ip:port/repository/maven-public/</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>snapshots</name>
<url>http://ip:port/repository/maven-public/</url>
<uniqueVersion>true</uniqueVersion>
</snapshotRepository>
</distributionManagement>
打包插件
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
打包时引入额外的jar包方案一
1、添加额外的引入包
<resources>
<resource>
<directory>jdbc-driver</directory>
<includes>
<include>**/*</include>
</includes>
<targetPath>../boot-lib</targetPath>
</resource>
</resources>
2、<Class-Path>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<excludes>
<exclude>logback-spring.xml</exclude>
<exclude>application*.properties</exclude>
</excludes>
<archive>
<manifest>
<mainClass>com.Application</mainClass>
<classpathPrefix>boot-lib/</classpathPrefix>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<Class-Path>boot-lib/opengauss-jdbc-5.0.3.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
打包时引入额外的jar包方案二
1、系统添加模拟pom文件
<dependency>
<groupId>org.opengauss</groupId>
<artifactId>opengauss-jdbc</artifactId>
<version>5.0.3</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/opengauss-jdbc-5.0.3.jar</systemPath>
</dependency>
2、<Class-Path>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<excludes>
<exclude>logback-spring.xml</exclude>
<exclude>application*.properties</exclude>
</excludes>
<archive>
<manifest>
<mainClass>com.Application</mainClass>
<classpathPrefix>boot-lib/</classpathPrefix>
<addClasspath>true</addClasspath>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
<manifestEntries>
<Class-Path>boot-lib/opengauss-jdbc-5.0.3.jar</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)