zoukankan      html  css  js  c++  java
  • 主要参考: https://stackoverflow.com/questions/5916157/how-to-get-the-maven-local-repo-location

    1. 如果是只需要查看本地仓库配置最终生效目录地址的话可以使用如下命令:(注意用于linux系统,在windows下去掉 | grep -v '
    INFO
    INFO
    ' 执行,不然会提示'grep' 不是内部或外部命令,也不是可运行的程序或批处理文件。)
    mvn help:evaluate -Dexpression=settings.localRepository | grep -v '[INFO]'


    2. 在运行maven命令时,添加-X 或者 -debug参数(注意区分大小写)
    mvn -X
    会打印出相关结果

    [INFO] Error stacktraces are turned on.
    [DEBUG] Reading global settings from D:devToolapache-maven-3.3.9confsettings.xml
    [DEBUG] Reading user settings from C:Userslk.m2settings.xml
    [DEBUG] Reading global toolchains from D:devToolapache-maven-3.3.9conf oolchains.xml
    [DEBUG] Reading user toolchains from C:Userslk.m2 oolchains.xml
    [DEBUG] Using local repository at D:path olocal epo
    [DEBUG] Using manager EnhancedLocalRepositoryManager with priority 10.0 for D:path olocal epo
    [INFO] Scanning for projects...
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://192.169.2.234:8081/repository/myself_hosted/
    [DEBUG] Using connector BasicRepositoryConnector with priority 0.0 for http://192.169.2.234:8081/repository/myself_hosted/ with username=deployment, password=***
    Downloading: http://192.169.2.234:8081/repository/myself_hosted/org/springframework/boot/spring-boot-starter-parent/2.4.2/spring-boot-starter-parent-2.4.2.pom
    [DEBUG] Writing tracking file D:path olocal epoorgspringframeworkootspring-boot-starter-parent2.4.2spring-boot-starter-parent-2.4.2.pom.lastUpdated
    [DEBUG] Using transporter WagonTransporter with priority -1.0 for http://maven.aliyun.com/nexus/content/repositories/central/

    可以看到 读取了两个位置的 settings.xml 配置,但是最终使用了  D:path olocal epo 作为  local repository !

    3. 使用如下命令可以查看当前Maven环境启用的文件(注意:首次使用开始会下载jar包,这很正常)
    mvn help:effective-settings
    这里的 <localRepository>D:softsmavenmvnRepository</localRepository>  就是我的本地仓库

    注意:窗口乱码情况可以通过添加环境变量

     

    或者在执行文件配置set MAVEN_OPTS=-Xms128m -Xmx512m -Dfile.encoding=UTF-8

    如果你没有做任何特殊配置的话,从Maven中心仓库下载到本地的jar包的默认存放在”${user.home}/.m2/repository”中,也可以修改settins.xml,自定义仓库目录

    4.查看当前项目的pom配置,包括所有依赖

    mvn help:effective-pom

     5. 指定使用某个配置文件执行Maven命令(这个就不截图)

    mvn -s <filepath> <goal>
    mvn -s ~/.m2/settings_local.xml clean deploy


    6. 检查环境(结合下面两个命令)

    # 查看当前项目的所有mvn配置
    mvn -X

    # 打印所有可用的环境变量和Java系统属性
    mvn help:system

    7. 查看当前处于激活状态的profile

    mvn help:active-profiles 

    settings.xml文件是干什么的,为什么要配置它呢?
    从settings.xml的文件名就可以看出,它是用来设置maven参数的配置文件。并且,settings.xml是maven的全局配置文件。而pom.xml文件是所在项目的局部配置。
    Settings.xml中包含类似本地仓储位置、修改远程仓储服务器、认证信息等配置。

    settings.xml文件位置
    settings.xml文件一般存在于两个位置:
    全局配置: ${M2_HOME}/conf/settings.xml
    用户配置: user.home/.m2/settings.xmlnote:用户配置优先于全局配置。

    {user.home} 和所有其他系统属性只能在3.0+版本上使用(请注意windows和Linux使用变量的区别)。

    mvn help:effective-settings

    配置优先级
    需要注意的是:局部配置优先于全局配置。
    配置优先级从高到低:pom.xml> user settings > global settings
    如果这些文件同时存在,在应用配置时,会合并它们的内容,如果有重复的配置,优先级高的配置会覆盖优先级低的。
    ————————————————
    版权声明:本文为CSDN博主「tyyking」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/tyyking/article/details/83008533

    ++++++++++++++++ 关于优先级 !+++++ 

    但是呢, 如果一个配置项只出现在 ${M2_HOME}/conf/settings.xml, 而没有user.home/.m2/settings.xml配置, 那么 还是使用${M2_HOME}/conf/settings.xml 的配置

    但是 pom.xml 优先级更高!
    但是,需要注意有些东西 不能配置在 pom.xml 里面!

    比如  下面只能在 pom.xml  里面: 

        <!--上传到nexus私服-->
        <distributionManagement>
            <repository>
                <id>myself_hosted</id>
                <name>myself_hosted repository</name>
                <url>http://192.169.2.24:8081/repository/myself_hosted/</url>
            </repository>
        </distributionManagement>
    
        <!--从nexus私服拉取jar包-->
        <repositories>
            <repository>
                <id>myself_hosted</id>
                <name>myself_hosted repository</name>
                <url>http://192.169.2.24:8081/repository/myself_hosted/</url>
            </repository>
        </repositories>

    另外distributionManagement 是表示 上传, 这个一定是必须的。 repositories 是表示 拉取, 其实呢, 也可以通过 settings.xml 的mirror 进行配置。


    版权声明
    本文原创发表于 博客园,作者为 阿K .     本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
    欢迎关注本人微信公众号:觉醒的码农,或者扫码进群:

  • 相关阅读:
    混合现实开发教程unity2017
    Intro to Airplane Physics in Unity 3D – 2017 and 2018
    Unity Awards 2018最佳资源
    ambiguous
    Unity2018.3全新Prefab预制件系统深入介绍视频教程+PPT+Demo源码
    Android Studio 集成开发工具教学视频 + 项目实战安卓多SDK接入与集成
    Unity下一轮最大的变革-Entity Component System & C# Jobs System
    使用unity开发游戏时如觉得游戏声音太吵,点Mute Audio
    SQL Delta实用案例介绍
    经典批处理实现自动关机(BAT)
  • 原文地址:https://www.cnblogs.com/FlyAway2013/p/15213198.html
Copyright © 2011-2022 走看看