Skip to content

Commit 8e8459e

Browse files
[PUBLISHER] Merge #160
1 parent 59bc4c0 commit 8e8459e

File tree

1 file changed

+311
-0
lines changed

1 file changed

+311
-0
lines changed
Lines changed: 311 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
---
2+
title: Macos通过homebrew安装maven
3+
date: 2024-05-06 00:34:10 +08:00
4+
filename: 2024-05-06-Macos-brew-install-maven
5+
categories:
6+
- Misc
7+
tags:
8+
- Environment
9+
- Java
10+
- macOS
11+
dir: Misc
12+
share: true
13+
---
14+
## 安装
15+
16+
在shell下输入
17+
```shell
18+
brew install maven
19+
```
20+
21+
然后你的maven就装好了,在终端中输入
22+
```shell
23+
mvn -version
24+
```
25+
26+
即可查看相关信息.
27+
28+
我用的是Macbook M1Pro,我的mvn主目录在`/opt/homebrew/Cellar/maven/3.9.8/libexec`,配置文件在`/opt/homebrew/Cellar/maven/3.9.8/libexec/conf/settings.xml`
29+
30+
31+
## 配置镜像源以及本地仓库
32+
33+
打开`Settings.xml`,我们修改`mirros`以及`localRepository`
34+
我的配置文件如下
35+
```xml
36+
<?xml version="1.0" encoding="UTF-8"?>
37+
38+
<!--
39+
Licensed to the Apache Software Foundation (ASF) under one
40+
or more contributor license agreements. See the NOTICE file
41+
distributed with this work for additional information
42+
regarding copyright ownership. The ASF licenses this file
43+
to you under the Apache License, Version 2.0 (the
44+
"License"); you may not use this file except in compliance
45+
with the License. You may obtain a copy of the License at
46+
47+
http://www.apache.org/licenses/LICENSE-2.0
48+
49+
Unless required by applicable law or agreed to in writing,
50+
software distributed under the License is distributed on an
51+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
52+
KIND, either express or implied. See the License for the
53+
specific language governing permissions and limitations
54+
under the License.
55+
-->
56+
57+
<!--
58+
| This is the configuration file for Maven. It can be specified at two levels:
59+
|
60+
| 1. User Level. This settings.xml file provides configuration for a single user,
61+
| and is normally provided in ${user.home}/.m2/settings.xml.
62+
|
63+
| NOTE: This location can be overridden with the CLI option:
64+
|
65+
| -s /path/to/user/settings.xml
66+
|
67+
| 2. Global Level. This settings.xml file provides configuration for all Maven
68+
| users on a machine (assuming they're all using the same Maven
69+
| installation). It's normally provided in
70+
| ${maven.conf}/settings.xml.
71+
|
72+
| NOTE: This location can be overridden with the CLI option:
73+
|
74+
| -gs /path/to/global/settings.xml
75+
|
76+
| The sections in this sample file are intended to give you a running start at
77+
| getting the most out of your Maven installation. Where appropriate, the default
78+
| values (values used when the setting is not specified) are provided.
79+
|
80+
|-->
81+
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
82+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
83+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
84+
<!-- localRepository
85+
| The path to the local repository maven will use to store artifacts.
86+
|
87+
| Default: ${user.home}/.m2/repository
88+
<localRepository>/path/to/local/repo</localRepository>
89+
-->
90+
<!-- 本地仓库 --><localRepository>/opt/homebrew/Cellar/maven/3.9.8/libexec/mvn_repo</localRepository>
91+
92+
<!-- interactiveMode
93+
| This will determine whether maven prompts you when it needs input. If set to false,
94+
| maven will use a sensible default value, perhaps based on some other setting, for
95+
| the parameter in question.
96+
|
97+
| Default: true
98+
<interactiveMode>true</interactiveMode>
99+
-->
100+
101+
<!-- offline
102+
| Determines whether maven should attempt to connect to the network when executing a build.
103+
| This will have an effect on artifact downloads, artifact deployment, and others.
104+
|
105+
| Default: false
106+
<offline>false</offline>
107+
-->
108+
109+
<!-- pluginGroups
110+
| This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
111+
| when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
112+
| "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
113+
|-->
114+
<pluginGroups>
115+
<!-- pluginGroup
116+
| Specifies a further group identifier to use for plugin lookup.
117+
<pluginGroup>com.your.plugins</pluginGroup>
118+
-->
119+
</pluginGroups>
120+
121+
<!-- TODO Since when can proxies be selected as depicted? -->
122+
<!-- proxies
123+
| This is a list of proxies which can be used on this machine to connect to the network.
124+
| Unless otherwise specified (by system property or command-line switch), the first proxy
125+
| specification in this list marked as active will be used.
126+
|-->
127+
<proxies>
128+
<!-- proxy
129+
| Specification for one proxy, to be used in connecting to the network.
130+
|
131+
<proxy>
132+
<id>optional</id>
133+
<active>true</active>
134+
<protocol>http</protocol>
135+
<username>proxyuser</username>
136+
<password>proxypass</password>
137+
<host>proxy.host.net</host>
138+
<port>80</port>
139+
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
140+
</proxy>
141+
-->
142+
</proxies>
143+
144+
<!-- servers
145+
| This is a list of authentication profiles, keyed by the server-id used within the system.
146+
| Authentication profiles can be used whenever maven must make a connection to a remote server.
147+
|-->
148+
<servers>
149+
<!-- server
150+
| Specifies the authentication information to use when connecting to a particular server, identified by
151+
| a unique name within the system (referred to by the 'id' attribute below).
152+
|
153+
| NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
154+
| used together.
155+
|
156+
<server>
157+
<id>deploymentRepo</id>
158+
<username>repouser</username>
159+
<password>repopwd</password>
160+
</server>
161+
-->
162+
163+
<!-- Another sample, using keys to authenticate.
164+
<server>
165+
<id>siteServer</id>
166+
<privateKey>/path/to/private/key</privateKey>
167+
<passphrase>optional; leave empty if not used.</passphrase>
168+
</server>
169+
-->
170+
</servers>
171+
172+
<!-- mirrors
173+
| This is a list of mirrors to be used in downloading artifacts from remote repositories.
174+
|
175+
| It works like this: a POM may declare a repository to use in resolving certain artifacts.
176+
| However, this repository may have problems with heavy traffic at times, so people have mirrored
177+
| it to several places.
178+
|
179+
| That repository definition will have a unique id, so we can create a mirror reference for that
180+
| repository, to be used as an alternate download site. The mirror site will be the preferred
181+
| server for that repository.
182+
|-->
183+
<mirrors>
184+
<!-- mirror
185+
| Specifies a repository mirror site to use instead of a given repository. The repository that
186+
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
187+
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
188+
|
189+
<mirror>
190+
<id>mirrorId</id>
191+
<mirrorOf>repositoryId</mirrorOf>
192+
<name>Human Readable Name for this Mirror.</name>
193+
<url>http://my.repository.com/repo/path</url>
194+
</mirror>
195+
-->
196+
<mirror>
197+
<id>maven-default-http-blocker</id>
198+
<mirrorOf>external:http:*</mirrorOf>
199+
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
200+
<url>http://0.0.0.0/</url>
201+
<blocked>true</blocked>
202+
</mirror>
203+
<!-- 阿里云 mirror -->
204+
<mirror>
205+
<id>nexus-aliyun</id>
206+
<mirrorOf>*</mirrorOf>
207+
<name>Nexus aliyun</name>
208+
<url>http://maven.aliyun.com/repository/public</url>
209+
</mirror>
210+
</mirrors>
211+
212+
213+
<!-- profiles
214+
| This is a list of profiles which can be activated in a variety of ways, and which can modify
215+
| the build process. Profiles provided in the settings.xml are intended to provide local machine-
216+
| specific paths and repository locations which allow the build to work in the local environment.
217+
|
218+
| For example, if you have an integration testing plugin - like cactus - that needs to know where
219+
| your Tomcat instance is installed, you can provide a variable here such that the variable is
220+
| dereferenced during the build process to configure the cactus plugin.
221+
|
222+
| As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
223+
| section of this document (settings.xml) - will be discussed later. Another way essentially
224+
| relies on the detection of a property, either matching a particular value for the property,
225+
| or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
226+
| value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
227+
| Finally, the list of active profiles can be specified directly from the command line.
228+
|
229+
| NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
230+
| repositories, plugin repositories, and free-form properties to be used as configuration
231+
| variables for plugins in the POM.
232+
|
233+
|-->
234+
<profiles>
235+
<!-- profile
236+
| Specifies a set of introductions to the build process, to be activated using one or more of the
237+
| mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
238+
| or the command line, profiles have to have an ID that is unique.
239+
|
240+
| An encouraged best practice for profile identification is to use a consistent naming convention
241+
| for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
242+
| This will make it more intuitive to understand what the set of introduced profiles is attempting
243+
| to accomplish, particularly when you only have a list of profile id's for debug.
244+
|
245+
| This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
246+
<profile>
247+
<id>jdk-1.4</id>
248+
249+
<activation>
250+
<jdk>1.4</jdk>
251+
</activation>
252+
253+
<repositories>
254+
<repository>
255+
<id>jdk14</id>
256+
<name>Repository for JDK 1.4 builds</name>
257+
<url>http://www.myhost.com/maven/jdk14</url>
258+
<layout>default</layout>
259+
<snapshotPolicy>always</snapshotPolicy>
260+
</repository>
261+
</repositories>
262+
</profile>
263+
-->
264+
265+
<!--
266+
| Here is another profile, activated by the property 'target-env' with a value of 'dev', which
267+
| provides a specific path to the Tomcat instance. To use this, your plugin configuration might
268+
| hypothetically look like:
269+
|
270+
| ...
271+
| <plugin>
272+
| <groupId>org.myco.myplugins</groupId>
273+
| <artifactId>myplugin</artifactId>
274+
|
275+
| <configuration>
276+
| <tomcatLocation>${tomcatPath}</tomcatLocation>
277+
| </configuration>
278+
| </plugin>
279+
| ...
280+
|
281+
| NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
282+
| anything, you could just leave off the <value/> inside the activation-property.
283+
|
284+
<profile>
285+
<id>env-dev</id>
286+
287+
<activation>
288+
<property>
289+
<name>target-env</name>
290+
<value>dev</value>
291+
</property>
292+
</activation>
293+
294+
<properties>
295+
<tomcatPath>/path/to/tomcat/instance</tomcatPath>
296+
</properties>
297+
</profile>
298+
-->
299+
</profiles>
300+
301+
<!-- activeProfiles
302+
| List of profiles that are active for all builds.
303+
|
304+
<activeProfiles>
305+
<activeProfile>alwaysActiveProfile</activeProfile>
306+
<activeProfile>anotherAlwaysActiveProfile</activeProfile>
307+
</activeProfiles>
308+
-->
309+
</settings>
310+
311+
```

0 commit comments

Comments
 (0)