IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

Apache Maven(七):settings.xml

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

settings.xml 文件中包含settings标签,这个标签可以配置如何去执行Maven。其中包括本地存储库位置,备用远程存储库服务器和身份验证信息等值。

有如下两个位置可能存放这settings.xml 文件:

  • Maven 安装目录:${maven.home}/conf/settings.xml
  • 用户的目录:${user.home}/.m2/settings.xml

前者的settings.xml 是一个全局的设置文件,后者的settings.xml 是一个用户设置文件,如果两者都存在的话,则将内容进行合并处理,并且用户的settings.xml 占主导地位。

如果你想创建一个用户的设置文件,那么最好的办法就是复制全局的设置文件到${user.home}/.m2/目录下,全局的maven设置文件是一个包含了注释的示例模板。因此可以通过它调整你需要的内容。

下面是设置文件的主要标签:

 <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
                           https://maven.apache.org/xsd/settings-1.0.0.xsd">
       <localRepository/>
       <interactiveMode/>
       <usePluginRegistry/>
       <offline/>
       <pluginGroups/>
       <servers/>
       <mirrors/>
       <proxies/>
       <profiles/>
       <activeProfiles/>
     </settings>

可以使用$ {user.home}和一些其他的系统属性值插入settings.xml属性中;${env.HOME}等环境变量。

简单设置

settings.xml设置一些简单是值,如下示例:

 <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
                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
   <localRepository>${user.home}/.m2/repository</localRepository>
   <interactiveMode>true</interactiveMode>
   <usePluginRegistry>false</usePluginRegistry>
   <offline>false</offline>
   ...
 </settings>
  • localRepository: 这个属性用来配置构建系统的本地存储库,默认值为:${user.home}/.m2/repository。
  • interactiveMode: Maven需要用户输入时,是否需要提示你。默认为true。
  • usePluginRegistry:如果你需要使用${user.home}/.m2/plugin-registry.xml文件来管理插件的版本,那么就设置为true。默认为false。
  • offline: 如果构建系统需要使用离线模式运行,则设置为true,默认为false。由于网络和安全问题,对于那些无法连接到远程存储库是很有用的。

pluginGroups

pluginGroups 标签包含pluginGroup标签列表,每一个pluginGroups标签包含一个groupId,当你使用插件并且在命令行中并没有提供groupId时,将搜索此列表。该列表自动包含org.apache.maven.plugins和org.codehaus.mojo的groupId。

 <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
                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
   ...
   <pluginGroups>
     <pluginGroup>org.mortbay.jetty</pluginGroup>
   </pluginGroups>
   ...
 </settings>

例如给出如上示例时,当Maven执行org.mortbay.jetty:jetty-maven-plugin:run命令时,可以直接使用如下命令执行:

mvn jetty:run

servers

下载和部署的存储库由POM的repositories 和 distributionManagement 元素定义。但某些值(如用户名或密码)不应该由POM设置,这种类型的信息应该存放在settings文件中。

 <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
                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
   ...
   <servers>
     <server>
       <id>server001</id>
       <username>my_login</username>
       <password>my_password</password>
       <privateKey>${user.home}/.ssh/id_dsa</privateKey>
       <passphrase>some_passphrase</passphrase>
       <filePermissions>664</filePermissions>
       <directoryPermissions>775</directoryPermissions>
       <configuration></configuration>
     </server>
   </servers>
   ...
 </settings>
  • id: 这是与Maven试图连接的存储库/镜像的id元素相匹配的服务器的标识(不是用户登录的标识)。
  • username,password:这些元素显示为一对,表示对此服务器进行身份验证所需的登录名和密码。
  • privateKey,passphrase:与前面的两个元素一样,如果需要,该对将指定私钥的路径(默认为${user.home}/.ssh/id_dsa)和密码。该passphrase和password的元素可能在将来被外部化,但现在他们必须设置在纯文本的settings.xml文件。
  • filePermissions,directoryPermissions:在部署时创建存储库文件或目录时,这些是要使用的权限。每一个的合法值都是与*nix文件权限对应的三位数字,例如664或775。

注:如果你使用私钥登录服务器,请确保省略了password元素,否则密钥不生效。

在Maven 2.1.0+ 添加了一项新功能,对password 和 passphrase进行加密。具体加密信息可以查看官方介绍

mirrors

<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
                      https://maven.apache.org/xsd/settings-1.0.0.xsd">
  ...
  <mirrors>
    <mirror>
      <id>planetmirror.com</id>
      <name>PlanetMirror Australia</name>
      <url>http://downloads.planetmirror.com/pub/maven2</url>
      <mirrorOf>central</mirrorOf>
    </mirror>
  </mirrors>
  ...
</settings>
  • id,name: 此镜像的唯一标识符ID和用户名。这个ID可以区分不同的mirror元素。并在连接镜像时从部分选择相应的凭据。
  • url: 此镜像的基本网址。构建系统将使用此URL来连接到存储库,而不是原始存储库URL。
  • mirrorOf: 这是中央存储库的ID。例如,要指向Maven 中央存储库(https://repo.maven.apache.org/maven2/)的镜像,则将该元素值设置为central。还有更多的值如:repo1,repo2 或 *,!inhouse,这个值不能与镜像id一样。

proxies

 <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
                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
   ...
   <proxies>
     <proxy>
       <id>myproxy</id>
       <active>true</active>
       <protocol>http</protocol>
       <host>proxy.somewhere.com</host>
       <port>8080</port>
       <username>proxyuser</username>
       <password>somepassword</password>
       <nonProxyHosts>*.google.com|ibiblio.org</nonProxyHosts>
     </proxy>
   </proxies>
   ...
 </settings>
  • id: 此代理的唯一标识ID,用来区分proxy元素。
  • active: 如果此代理处于活动状态,则设置为true。这对于声明一堆代理非常有用,但一次只能激活一个代理。
  • protocol,host,port: 协议,主机,端口。
  • username,password:这表示一对,用来验证此代理服务器所需要的用户名和密码。
  • nonProxyHosts: 这是不需要代理的主机列表。使用|进行分割,也可以使用逗号分隔。

Profiles

settings.xml 中的profile元素可以截断 pom.xml 的profile元素。它包含activation, repositories, pluginRepositories 和 properties 元素。该profile元素仅包含这四个元素,因为它们与构建系统作为一个整体,不是单个项目的设置。

如果某个prefile在settings.xml中处于激活状态,则其值将会覆盖POM 或 profile.xml文件中相同ID的profile值。

 <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
                       https://maven.apache.org/xsd/settings-1.0.0.xsd">
   ...
   <profiles>
     <profile>
       <id>test</id>
       <activation>
         <activeByDefault>false</activeByDefault>
         <jdk>1.5</jdk>
         <os>
           <name>Windows XP</name>
           <family>Windows</family>
           <arch>x86</arch>
           <version>5.1.2600</version>
         </os>
         <property>
           <name>mavenVersion</name>
           <value>2.0.3</value>
         </property>
         <file>
           <exists>${basedir}/file2.properties</exists>
           <missing>${basedir}/file1.properties</missing>
         </file>
       </activation>
       ...
     </profile>
   </profiles>
   ...
 </settings>
  • jdk:activation 在jdk元素中内置了一个以Java为中心的检查。如果测试在与给定前缀相匹配的jdk版本号下运行,这将激活。在上面的例子中,1.5.0_06将匹配。
  • os:os元素可以定义上面显示的某些操作系统特定的属性。
  • property: 如果Maven检测到相应的name = value对的属性(可以在POM中取消$ {name}的值),该配置文件将激活。
  • file:最终,一个给定的文件名可能通过文件的存在或缺失来激活配置文件。

文章永久链接:https://tech.souyunku.com/?p=13820


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(91) 打赏



未经允许不得转载:搜云库技术团队 » Apache Maven(七):settings.xml

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367