【问题标题】:How to resolve project library via own mvn repository (artifactory)如何通过自己的 Maven 存储库(工件)解析项目库
【发布时间】:2014-08-27 22:32:28
【问题描述】:

如何将我们在内部设置的 Maven 存储库与我的 Intellij 链接?

在项目库视图中,我能够添加一个位于标准 maven 存储库中的新项目库,但我看不到如何将 IntelliJ 指向特定的 maven 存储库,例如我们为公司。

Intellij 也无法识别 Settings.xml。之后我发布了 settings.xml,但它无法识别(密码、用户名和公司名称已被替换):

<settings>
    <servers>
        <server>
            <username>USER</username>
            <password>PW</password>
            <id>central</id>
        </server>
    </servers>
    <mirrors>
        <mirror>
            <mirrorOf>*</mirrorOf>
            <url>
https://dev.mycompany.com:8443/artifactory/any
            </url>
            <id>central</id>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <repositories>
                <repository>
                    <snapshots />
                    <id>central</id>
                    <url>
https://dev.mycompany.com:8443/artifactory/libs
                    </url>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <snapshots />
                    <id>central</id>
                    <url>
https://dev.mycompany.com:8443/artifactory/plugins
                    </url>
                </pluginRepository>
            </pluginRepositories>
            <id>artifactory</id>
        </profile>
    </profiles>
    <activeProfiles>
        <activeProfile>artifactory</activeProfile>
    </activeProfiles>
</settings>

【问题讨论】:

  • 为什么不在pom.xml 中定义一个新的仓库? IntelliJ 会很好地获取它
  • 我想这样做,但当前项目是一个旧的单体遗留 ant 项目。 pom.xml 等花哨的东西目前不存在。当然我可以找到一种解决方法,但另一方面我也想告诉 IntelliJ 使用内部 maven 存储库。

标签: intellij-idea dependencies setup-project


【解决方案1】:

IntelliJ 将来自 pom.xml 的存储库用于您的 maven 项目和 settings.xml,您的 maven 配置文件。为了从存储库中获取依赖关系并且不添加pom.xml,我相信您应该在设置文件中定义存储库。

默认情况下,此文件位于您的主文件夹中,例如 {home}/.m2/settings.xml

尝试添加此配置:

<settings>
 ...
 <profiles>
   ...
   <profile>
     <id>myprofile</id>
     <activation>
        <activeByDefault>true</activeByDefault>
     </activation>
     <repositories>
       <repository>
         <id>my-repo2</id>
         <name>your custom repo</name>
         <url>http://jarsm2.dyndns.dk</url>
       </repository>
     </repositories>
   </profile>
   ...
 </profiles>

 <activeProfiles>
   <activeProfile>myprofile</activeProfile>
 </activeProfiles>
 ...
</settings>

还请记住,您应该在使用 maven 时使用配置文件或将其默认激活。查看更多信息here

【讨论】:

  • 感谢您的回答!我增强了我的初始帖子,因为实际上我们已经这样做了,但是 IntelliJ 无法识别 settings.xml
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-09-26
  • 2020-10-07
  • 2011-11-05
  • 1970-01-01
  • 2015-07-24
相关资源
最近更新 更多