服务于Java平台构建、依赖管理、项目管理,通过xml格式配置文件管理
下载安装
#上传tar包
tar -zxvf apache-maven-3.3.9-bin.tar.gz && mv apache-maven-3.3.9 /usr/local
#创建软链接
ln -s /usr/local/apache-maven-3.3.9 /usr/local/maven
#添加maven环境变量
echo 'export PATH=/usr/local/maven/bin/:$PATH' >> /etc/profile && source /etc/profile
常用操作
mvn -v #查看版本号
mvn clean #清理上次的编译结果
mvn package #打包
mvn validate(验证):验证项目正确,并且所有必要信息可用。
mvn compile(编译):编译项目源码
mvn test(测试):使用合适的单元测试框架测试编译后的源码。
mvn integration-test(集成测试):如果有需要,把包处理并部署到可以运行集成测试的环境中去。
mvn verify(验证):进行各种测试来验证包是否有效并且符合质量标准。
mvn install(安装):把包安装到本地仓库,使该包可以作为其他本地项目的依赖。
mvn deploy(部署):在集成或发布环境中完成,将最终软件包复制到远程存储库,以与其他开发人员和项目共享。
配置阿里云服务器
mirror标签指向阿里云
/maven/conf/settings.xml
#打开配置文件找到相应的mirror标签,加入对应的配置
<mirror>
<id>aliyun</id>
<name>aliyun</name>
<mirrorOf>*</mirrorOf>
<url>https://maven.aliyun.com/repository/public</url>
</mirror>
#项目中测试
mvn package
创建maven私服Nexus
官网:https://www.sonatype.com/download-oss-sonatype
默认端口:8081
项目下的pom.xml配置只生效于当前项目
在maven配置全局生效
安装jdk和nexus
上传jdk和nexus安装包
安装jdk,并配置jdk的环境变量 /etc/profile
tar -zxvf nexus-3.17.0-01-unix.tar.gz && mv nexus-3.17.0-01 /usr/local
ln -s /usr/local/nexus-3.17.0-01 /usr/local/nexus
cd /usr/local/nexus/bin && ./nexus start
ps:这里启动需要一点时间,请耐心等待~
#查看默认的nexus密码
cat /usr/local/sonatype-work/nexus3/admin.password
#用admin用户和默认密码登录系统
nexus后台配置全局代理
修改maven 配置文件
/usr/local/maven/conf/settings.xml
修改 servers标签 mirrors标签 profiles标签 activeProfiles标签
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
</pluginGroups>
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
</proxies>
<servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<name>nexus maven</name>
<url>http://192.168.31.238:8081/repository/maven-public/</url>
<mirrorOf>*</mirrorOf>
</mirror>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>https://maven.aliyun.com/repository/public</url>
<mirrorOf>central</mirrorOf>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<url>https://maven.aliyun.com/repository/public</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url>http://192.168.31.238:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<!--profile的id-->
<id>nexus-releases</id>
<repositories>
<repository>
<!--仓库id,repositories可以配置多个仓库,保证id不重复-->
<id>nexus-releases</id>
<!--仓库地址,即nexus仓库组的地址-->
<url>http://192.168.31.238:8081/repository/maven-releases/</url>
<!--是否下载releases构件-->
<releases><enabled>true</enabled></releases>
<!--是否下载snapshots构件-->
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
<pluginRepository>
<!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
<id>nexus-releases</id>
<url>http://192.168.31.238:8081/repository/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<profile>
<id>nexus-snapshots</id>
<repositories>
<repository>
<id>nexus-snapshots</id>
<url>http://192.168.31.238:8081/repository/maven-snapshots/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://192.168.31.238:8081/repository/maven-snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>nexus-releases</activeProfile>
<activeProfile>nexus-snapshots</activeProfile>
</activeProfiles>
</settings>