文档首页> CodeArts IDE> 常见问题> CodeArts IDE for Java> 默认的Maven配置文件settings.xml配置参考
更新时间:2024-06-24 GMT+08:00
分享

默认的Maven配置文件settings.xml配置参考

请参考此章节说明中的settings.xml文件配置参考中的配置,若要使用参考配置,可以在“用户路径/.m2”文件夹下,新建或替换settings.xml文件,Java语言服务会默认读取此路径下的maven配置文件。

也可以自定义此settings.xml文件存放路径,然后在工程中指定具体的settings.xml文件的路径,参考如下步骤:

  1. 单击左侧活动栏下方管理->Java智能助手设置

  2. Java智能助手设置中,单击“构建工具”,找到Maven相关设置,替换用户设置文件即可。

settings.xml文件配置参考:

<?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">
	<!-- 默认的值是${user.home}/.m2/repository -->
	<!--<localRepository></localRepository>-->
	<!-- 如果Maven要试图与用户交互来得到输入就设置为true,否则就设置为false,默认为true。 -->
	<!--
	<interactiveMode>true</interactiveMode>
	-->
	<!-- 如果Maven使用${user.home}/.m2/plugin-registry.xml来管理plugin的版本,就设置为true,默认为false。 -->
	<!--
	<usePluginRegistry>false</usePluginRegistry>
	-->
	<!-- 如果构建系统要在离线模式下工作,设置为true,默认为false。 如果构建服务器因为网络故障或者安全问题不能与远程仓库相连,那么这个设置是非常有用的。 -->
	<!--
	<offline>false</offline>
	-->
	<servers>
		<!-- server
		| Specifies the authentication information to use when connecting to a particular server,
				identified by
		| a unique name within the system (referred to by the 'id' attribute below).
		|
		| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings
				are
		|       used together.
		|
		-->
		<!-- server标签的作用 ,如下 -->
		<!-- 使用mvn install时,会把项目打的包安装到本地maven仓库 -->
		<!-- 使用mvn deploye时,会把项目打的包部署到远程maven仓库,这样有权限访问远程仓库的人都可以访问你的jar包 -->
		<!-- 通过在pom.xml中使用 distributionManagement 标签,来告知maven 部署的远程仓库地址,-->
	</servers>
	<mirrors>
		<mirror>
			<id>huaweiyun</id>
			<mirrorOf>*</mirrorOf><!--*代表所有的jar包都到华为云下载-->
			<!--<mirrorOf>central</mirrorOf>--><!--central代表只有中央仓库的jar包才到华为云下载-->
			<!-- maven 会有默认的id为 “central” 的中央仓库-->
			<name>huaweiyun-maven</name>
			<url>https://mirrors.huaweicloud.com/repository/maven/</url>
		</mirror>
	</mirrors>
	<!-- settings.xml中的profile是pom.xml中的profile的简洁形式。
	它包含了激活(activation),仓库(repositories),插件仓库(pluginRepositories)和属性(properties)元素。
profile元素仅包含这四个元素是因为他们涉及到整个的构建系统,而不是个别的POM配置。
	如果settings中的profile被激活,那么它的值将重载POM或者profiles.xml中的任何相等ID的profiles。 -->
	<!-- 如果setting中配置了 repository,则等于项目的pom中配置了 -->
	<profiles>
		<profile>
			<!-- 指定该 profile的id -->
			<id>dev</id>
			<!-- 远程仓库-->
			<repositories>
				<!-- 华为云远程仓库-->
				<repository>
					<id>huaweicloud</id>
					<name>huaweicloud maven Repository</name>
					<url>https://mirrors.huaweicloud.com/repository/maven/</url>
					<!-- 只从该仓库下载 release版本 -->
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</repository>
				<repository>
					<id>spring-milestone</id>
					<name>Spring Milestone Repository</name>
					<url>https://repo.spring.io/milestone</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
					<layout>default</layout>
				</repository>
				<repository>
					<id>spring-snapshot</id>
					<name>Spring Snapshot Repository</name>
					<url>https://repo.spring.io/snapshot</url>
					<releases>
						<enabled>false</enabled>
					</releases>
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
					<layout>default</layout>
				</repository>
			</repositories>
			<pluginRepositories>
				<!-- 插件仓库。插件从这些仓库下载 -->
				<pluginRepository>
					<id>huaweicloud</id>
					<url>https://mirrors.huaweicloud.com/repository/maven/</url>
					<releases>
						<enabled>true</enabled>
					</releases>
					<snapshots>
						<enabled>false</enabled>
					</snapshots>
				</pluginRepository>
			</pluginRepositories>
		</profile>
	</profiles>
	<!-- activations是profile的关键,就像POM中的profiles,profile的能力在于它在特定情况下可以修改一些值。
而这些情况是通过activation来指定的。 -->
	<!-- <activeProfiles/> -->
	<activeProfiles>
		<activeProfile>dev</activeProfile>
	</activeProfiles>
</settings>

分享:

CodeArts IDE for Java 所有常见问题

more