英文:
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:
<?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>
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
:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
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).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论