其他分享
首页 > 其他分享> > idea maven 无法导包

idea maven 无法导包

作者:互联网

maven 配置

阿里云镜像配置:

<mirrors>
        <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/central
        </url>
        <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/public
        </url>
        <mirrorOf>jcenter</mirrorOf>
    </mirror>    
    
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/public
        </url>
        <mirrorOf>public</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/google
        </url>
        <mirrorOf>google</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/gradle-plugin
        </url>
        <mirrorOf>gradle-plugin</mirrorOf>
    </mirror>

     <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/spring
        </url>
        <mirrorOf>spring</mirrorOf>
    </mirror>

        <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/spring-plugin
        </url>
        <mirrorOf>spring-plugin</mirrorOf>
    </mirror>


    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/grails-core
        </url>
        <mirrorOf>grails-core</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/apache-snapshots
        </url>
        <mirrorOf>apache-snapshots</mirrorOf>
    </mirror>

  </mirrors>

maven代理配置(有代理可以可学上网的配置)

  <proxies>
      <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>10809</port>
    </proxy>
    
  </proxies>

本地仓库配置

  <localRepository>C:\Software\apache-maven-3.8.1\repository</localRepository>

idea中项目的maven配置
新项目
在删掉.iml文件后maven配置根据这个生成
在这里插入图片描述
有时候包下载了但插件还是报红,可以试试把项目根目录的.iml 文件删除重新自动生成。
可以
idea maven 运行会读取两个地方的配置文件通过命令mvn install -X 可以查看

在这里插入图片描述
在这里插入图片描述
可以看到加载了.m2和conf下的setting.xml文件他会把两个文件都加载进来,所以配置有时候会混乱
建议一个配置文件配置代理,一个文件配置镜像,用其中一个的时候把另一个文件改个名字入改成settings.xmll避免干扰。
这样配置能解决大多问题,但有些包还是导入不了,需要查看是不是有冲突,或者dependency顺序的问题,有的博客说阿里云镜像改用https需要设置忽略ssl 验证。
最后是两个配置文件

<?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">
  
  <pluginGroups>

  </pluginGroups>

  <proxies>
      <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>127.0.0.1</host>
      <port>10809</port>
    </proxy>
    
  </proxies>

  <servers>
      <server>
          <id>releases</id>
          <username>admin</username>
          <password>admin123</password>
      </server>
      <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
  </servers>


  <localRepository>C:\Software\apache-maven-3.8.1\repository</localRepository>

  <mirrors>


  </mirrors>

  <profiles>
    
  </profiles>


</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">
  
  <pluginGroups>

  </pluginGroups>

  <proxies>


    
  </proxies>

 
  <servers>
      <server>
          <id>releases</id>
          <username>admin</username>
          <password>admin123</password>
      </server>
      <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>admin123</password>
    </server>
  </servers>



  <localRepository>C:\Software\apache-maven-3.8.1\repository</localRepository>

  <mirrors>
        <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/central
        </url>
        <mirrorOf>central</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/public
        </url>
        <mirrorOf>jcenter</mirrorOf>
    </mirror>    
    
    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/public
        </url>
        <mirrorOf>public</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/google
        </url>
        <mirrorOf>google</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/gradle-plugin
        </url>
        <mirrorOf>gradle-plugin</mirrorOf>
    </mirror>

     <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/spring
        </url>
        <mirrorOf>spring</mirrorOf>
    </mirror>

        <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/spring-plugin
        </url>
        <mirrorOf>spring-plugin</mirrorOf>
    </mirror>


    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/grails-core
        </url>
        <mirrorOf>grails-core</mirrorOf>
    </mirror>

    <mirror>
        <id>alimaven</id>
        <name>aliyun maven</name>
        <url>
            https://maven.aliyun.com/repository/apache-snapshots
        </url>
        <mirrorOf>apache-snapshots</mirrorOf>
    </mirror>

  </mirrors>

  <profiles>
    
  </profiles>

</settings>

标签:https,repository,idea,maven,导包,aliyun,alimaven,com
来源: https://blog.csdn.net/qq_42277477/article/details/121051787