Maven与IDEA版本兼容问题以及配置

        

        在创建Maven项目或者SpringBoot项目的时候,需要配置Maven插件。它能够为我们自动提供依赖,只需要几行代码提供jar包的坐标即可,而不用像以前那样疯狂导包,消耗多余的内存。

        maven版本与idea版本存在兼容性问题,版本不兼容就会报无法导入maven项目的问题。

Unable to import maven project: See logs for details

        IDEA 2018版本只兼容Maven3.6.1之前的版本,对于之后的版本不兼容。

        maven下载的官网地址是:https://maven.apache.org/download.cgi

         进入官网后可以看到目前maven的版本已经更新到了3.8.1,这个版本兼容的IDEA版本是2021,下载Maven3.6.1的步骤如下:

        首先点击Previous Releases里面的archives标签,进入maven3的索引页面

         然后点击3.6.1版本,进入3.6.1的索引页面。

         再点击binaries,进入binaries目录。最后windows系统点击apache-maven-3.6.1-bin.zip就可以开始下载maven3.6.1的压缩包了。

 

         下载完成后,将压缩包解压到电脑上存放软件开发工具的目录。然后进行maven插件的环境变量的配置。

        创建两个用户变量:

         点击确定。打开命令提示符:输入mvn -v检查maven环境变量是否配置成功。

Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: D:\DevelopTools\apache-maven-3.6.1\bin\..
Java version: 1.8.0_131, vendor: Oracle Corporation, runtime: D:\DevelopTools\jdk-1.8.0\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

         环境变量配置完成后,进行maven的配置文件settings.xml的配置。

         第一步:打开maven解压目录下的D:\DevelopTools\apache-maven-3.6.1\conf\settings.xml文件。在 <!--< localRepository></ localRepository>-->标签下配置本地仓库的地址,建议新建一个本地仓库目录进行配置。

<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">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  -->
  <localRepository>D:\DevelopTools\LocalRepository</localRepository>

        第二步:为了使maven能够自动从中央仓库下载需要的jar包,我们需要给它配置阿里云镜像仓库:在  settings.xml 文件的标<mirrors></mirrors>标签里面配置以下标签:

<mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
<mirrors>
      <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>
  </mirrors>

  </mirrors>

        第三步:将maven项目创建的默认依赖JDK版本改为1.8.

<profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->
<profiles>
         <profile>
              <id>jdk-1.8</id>
              <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
              </activation>
              <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
              </properties>
         </profile>
  </profiles>

         最后修改maven插件的设置,选择自己安装的maven,不使用IDEA自带的maven插件。图中的版本应该为我们安装的3.6.1。

        点击OK。

        接着创建一个HelloWorld的maven项目,输入项目的GroupId和ArtifactId,完成项目创建。

        接着在maven项目的porm.xml文件中配置相关依赖的坐标,导入某些依赖的坐标时可能会导入不成功,体现为书写的坐标全为红色,这时,只需要把依赖的坐标书写完整,右键porm.xml,选择maven下的reimport,需要等待一会儿的依赖下载,下载完成之后整个HelloWorld的maven工程就建立好了。

 <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
    </parent>


    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
    </dependencies>

         此外,可以将maven/importing设置里面的sources和Documentation的自动下载选项勾上,这样就可以设置当前项目自动下载相关包的功能。

 

  • 9
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
IdeaMaven版本不兼容是指在使用Idea开发工具进行项目开发时,所使用的Maven版本Idea工具不匹配或不支持。这可能导致项目无法正常构建、依赖无法下载、编译错误等问题。 兼容性问题的出现可能是由于以下原因: 1. Idea版本较旧:如果您使用的是较新版本Maven,但是Idea工具版本较旧,那么Idea可能不支持或无法识别最新的Maven功能和配置项。 2. Maven版本较旧:相反,如果您使用的是较新版本Idea工具,但是Maven版本较旧,那么Maven可能不支持或无法识别Idea工具所使用的某些功能和插件。 解决此问题的方法有: 1. 更新IdeaMaven:建议您首先检查您正在使用的IdeaMaven版本,并尝试更新到最新版本。通过使用相同或兼容的版本,可以更好地解决兼容性问题。 2. 配置IdeaMaven插件:在Idea中,您可以通过打开"Preferences"或"Settings"对话框,并在"Maven"选项卡下配置相应的Maven插件。确保插件版本与您正在使用的Maven版本相匹配。 3. 修改项目配置:如果问题仅出现在特定的项目中,您可以尝试修改项目中的Maven配置文件(pom.xml)或Idea配置文件,以满足兼容性要求。 4. 向社区寻求帮助:如果以上方法无法解决问题,您可以向IdeaMaven的官方社区寻求帮助。在这些社区中,您可以提出问题并获得专家或其他用户的解答和建议。 总之,IdeaMaven版本不兼容可能导致许多问题,但通过更新工具版本配置插件和修改项目配置等方法,您应该能够解决这些兼容性问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值