为什么在Intellij中通过Maven Artifact搜索添加依赖无法正常工作?

huangapple go评论73阅读模式
英文:

Why is adding a dependency with Intellij in the Maven Artifact search not working?

问题

我正在尝试在我的项目中设置Spring Boot。我正在使用@Repository注解,并在IntelliJ中使用添加依赖弹出窗口进行搜索 - 它位于发布版本5.2.8的org.springframework.stereotype类下。我点击Add,因为这是我需要的依赖关系,但什么都没有发生。

我该如何解决这个问题?我注意到在我的pom.xml文件中,我只能添加2.3.2版本的Spring Boot Starter Parent版本,而不能添加更新的版本。

查看我的pom.xml文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://ma––ven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>spring-boot-project-test</artifactId>
    <version>1.0-SNAPSHOT</version>

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

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.2.8.RELEASE</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

根据之前的问题,我删除了.m2目录,并将使用brew重新安装Maven - 我正在使用Mac OS。我直接从Spring Boot示例页面添加了这个代码片段,但它没有解析到发布版本。它只解析版本2.3.2

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.3.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

我还使用Spring Initializer使用了版本2.3.4,并且我在IntelliJ中直接打开了这个项目 - 我在其中遇到了相同的问题,即无法找到2.3.4的spring-boot-starter-parent版本。

英文:

I am trying to set up Spring boot in my project. I am using the @Repository annotation and searching for it using the add dependency pop up in intellij - it is under the org.springframework.stereotype class in release 5.2.8. I click Add as this is the dependency I need and nothing happens.

How do I resolve this issue? Another thing I noticed in my pom.xml file the only Spring boot starter parent version I can add is 2.3.2 and not later versions.

See my pom.xml file below:

 &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
 &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
     xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
     xsi:schemaLocation=&quot;http://ma––ven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

&lt;groupId&gt;org.example&lt;/groupId&gt;
&lt;artifactId&gt;spring-boot-project-test&lt;/artifactId&gt;
&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.3.2.RELEASE&lt;/version&gt;
&lt;/parent&gt;


&lt;properties&gt;
    &lt;java.version&gt;1.8&lt;/java.version&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
    &lt;/dependency&gt;

    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
        &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
        &lt;scope&gt;test&lt;/scope&gt;
        &lt;exclusions&gt;
            &lt;exclusion&gt;
                &lt;groupId&gt;org.junit.vintage&lt;/groupId&gt;
                &lt;artifactId&gt;junit-vintage-engine&lt;/artifactId&gt;
            &lt;/exclusion&gt;
        &lt;/exclusions&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
        &lt;groupId&gt;org.springframework&lt;/groupId&gt;
        &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
        &lt;version&gt;5.2.8.RELEASE&lt;/version&gt;
    &lt;/dependency&gt;
&lt;/dependencies&gt;

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
            &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

</project>

Looking at previous questions I deleted the .m2 directory and will reinstall maven with brew - I'm using Mac OS. I added this snippet directly from the Spring boot example page and it's not resolving the release version. It only resolves version 2.3.2:

&lt;parent&gt;
    &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
    &lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
    &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
&lt;/parent&gt;

I've also used Spring Initalizer to use version 2.3.4 and I open this project directly in intellij - I am getting the same problem in that it cannot find 2.3.4 spring-boot-starter-parent release.

答案1

得分: 1

IntelliJ自带了一个捆绑的Maven,因此请确保通过在IntelliJ中配置Maven设置来使用您实际想要使用的Maven(在已安装的Maven和捆绑的Maven之间选择)。可能默认情况下您正在使用捆绑的Maven,所以您需要点击Maven选项卡(右上角)上的重新加载按钮。

英文:

IntelliJ comes with a bundled maven, so make sure you use the one you actually want(between the installed one and the bundled one) by configuring the Maven settings in IntelliJ. Probably you are using the bundled one by default, so you have to hit the reload button on the maven tab(upper right).

huangapple
  • 本文由 发表于 2020年9月23日 17:58:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/64025434.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定