ComponentLookupException when importing java project into intellij Idea - java

I just download a spring boot project from https://start.spring.io/ and imported it into intellij idea, then I choose import module selecting the pom.xml file but when I click on Apply I get the error:
java.lang.RuntimeException: java.lang.RuntimeException: org.codehaus.plexus.component.repository.exception.ComponentLookupException: com.google.inject.ProvisionException: Unable to provision, see the following errors:
Here's the 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://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>org.springframework.amqp.tutorials</groupId>
<artifactId>rabbitmq-amqp-tutorials</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>rabbitmq-amqp-tutorials</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<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>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
EDIT:SOLUTION
As pointed out by #Sanura Hettiarachchi there is a bug with the edition of intellij idea I was using, uninstalling and installing the latest version (Intellij Idea 2022.2.3 Community Edition) solved the problem. Now importing an existing project works nicely, no need to manually import modules.

It's not clear what you are trying to achieve. You click "open or import" and add the existing project. After that you try to import the same project again.
If you want to load the maven dependancies right click on the "pom.xml" and select "maven->reload project"
Update:
The issue seems to be on intelliJ IDE older versions which should be fixed by now.
https://youtrack.jetbrains.com/issue/IDEA-290419/Maven-385-NoSuchMethodError-orgapachemavenmodelvalidationDefaultModelValidator-method-void-init-not-found

Related

Unable to use java.net.http in Maven project using Spring Java 12

I am trying to use java.net.http library to use HTTP functions, however my IntelliJ compiler is not recognizing it.
The error I receive on the package side: java: error: "invalid target release: 12"
in regards to the entire project here is another error that I receive: Plugin 'org.springframework.boot:spring-boot-maven-plugin:' not found
I have made sure I properly installed Java 12 as well as set it as the project & target bytecode version. Im relatively new to coding in this environment so if there's anything I can do to better describe my question please let me know.
Here is the maven pom.xml file:
<?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://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>io.rooseveltthedev</groupId>
<artifactId>coronavirus-tracker</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>coronavirus-tracker</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>12</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is the code where I am having difficulty with the HTTP import:
import java.net.http.HttpClient;
public class CoronaVirusDataService {
public static String VIRUS_DATA_URL = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv";
public void fetchVirusData(){
HttpClient client = HttpClient.newHttpClient();
}
}
also I noticed there are some lines that refuse to go into the code formatting any remarks on how to fix that for future questions would be great.
This should be some maven project / compiler and/or class-path related issue in your development environment.
I could not reproduce your error.
I am successfully using java.net.http.HttpClient with Spring Boot 2.4 and Java 12 (also Java 11 LTS!). HttpClient is connecting getting back 200 status codes...
Any issues you have is not related to java.net.http libraries with Spring Boot and Java 12...
I would try to mvn compile and package using command line without the IDE. Also, do you need spring boot dev-tools runtime dependency in your pom? Try to remove it...

Exception in thread "Thread-2" java.lang.NoSuchMethodError: kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;) for PACT tests

I'm getting this kotlin exception when trying to run some PACT tests using Java and not sure how to fix it please.
Here the error :
Exception in thread "Thread-2" java.lang.NoSuchMethodError:
kotlin.io.ByteStreamsKt.readBytes(Ljava/io/InputStream;)[B
EDIT
I've updated my PACT dependencies to use more up to date versions, and I'm still getting the same issue, however only when I have the below dependency as part of it and not sure why.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
This is my current pom:
<?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://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hmhco</groupId>
<artifactId>update-catalog</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
</parent>
<properties>
<rest-assured.version>3.0.0</rest-assured.version>
<json-schema-validator.version>3.3.0</json-schema-validator.version>
</properties>
<dependencies>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>${rest-assured.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>json-schema-validator</artifactId>
<version>${json-schema-validator.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-consumer-junit5</artifactId>
<version>4.0.10</version>
</dependency>
<dependency>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-junit</artifactId>
<version>4.0.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>au.com.dius</groupId>
<artifactId>pact-jvm-provider-maven</artifactId>
<version>4.0.10</version>
<configuration>
<pactDirectory>target/pacts</pactDirectory>
<pactBrokerUrl>http://pact-broker-hmh.devel.hmheng-qe.brnp.internal/</pactBrokerUrl>
<projectVersion>${project.version}</projectVersion>
<trimSnapshot>true</trimSnapshot>
</configuration>
</plugin>
</plugins>
</build>
And that's what I see when look for Kotlin after running maven dependency tree. The complete project can be found here.
Thanks very much.
A possible reason you are getting that error (I'm assuming) is because you are mixing major versions of the Pact libraries.
<pact.version>3.5.24</pact.version>
<pact-jvm-provider-maven.version>3.5.9</pact-jvm-provider-maven.version>
<pact-jvm-maven.version>3.5.24</pact-jvm-maven.version>
<pact.jvm.consumer.junit.version>4.0.10</pact.jvm.consumer.junit.version>
You have versions 3.5.9, 3.5.24 and 4.0.10. You should use the same major version.
Versions 3.5.x are mostly written in Kotlin (probably version 1.2.x), while version 4.0.x is written using Kotlin 1.3.x.
I'm not sure why Sprinboot is impacting things, but maybe a Spring dependency is also bringing in a version of the Kotlin standard library.
The best thing to do is use version 4.0.10 for all the Pact libraries, then run the Maven dependency tree plugin and check that versions of the Kotlin standard libraries that are being used.

error:java package xxx does not exist despite IDEA being aware of them

I'm leanring springboot with some source code.Recent days,when I begin learning new lessons and want to import the example project I found I fail to import all the packages when I open the example project. Although previous example projects works fine.
It's especially strange that the editor actually can identify those packages - it even offered me the appropriate classes when I manually deleted the import statements, I can see the library in the Project tree under External Libraries,I even can skip to see where the package is through ctrl+click. However, I always get a list of "java: package ... does not exist" upon compilation.How should I solve the problem?Thanks!!
I hava tried following solutions:
reimport in maven settings
invalidate and restart
3.check pom.xml
my pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neo</groupId>
<artifactId>spring-boot-file-upload</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.5.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-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
some of the wrong import
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MultipartException;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
error messages while compiling:
fail to import all the packages
therefore can't resolve all the related symbols
Your project is missing some dependencies. You are not only using Spring Boot, but also Spring Web and Spring MVC.
Try adding this to your pom.xml:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.9.RELEASE</version>
</dependency>
You may want to adapt depending on the Spring version you are using.

how to add dom4j dependecy in maven pom with spring boot

I want to use dom4j to parse xml string. But when I add dom4j dependency in pom file, my dev tool(Eeclipse) prompt errors below:
I tried to refresh project and maven's update project, the errors still occured. If remove the dependency, all of errors disappear, also dom4j cannot use.
Eclipse version:
Eclipse Java EE IDE for Web Developers.
Version: Photon Release (4.8.0)
Build id: 20180619-1200
POM file:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Maven Version:
I figured out it through a whole day working, the fix steps are:
1. the first line of errors prompt in eclipse is : fail to read artifact descriptor for xml-apis:xml-apis:jar:1.4.01.(the first capture image of the question)
2. I assumed that something are wrong with xml-apis in maven repository, so I find the directory of xml-apis in maven repository and remove them all
3. After that, I use Maven->Update project in eclipse, the errors run away.
I think the reason is: some files of xml-apis were damaged.

Thymeleaf dependency causes "Error: Could not find or load main class" in Spring tool suite

I've just downloaded STS and started some maven project and it worked properly, but when I start using thymeleaf it doesn't work.
I see an exclamation mark on the project name, and I get this error Error: Could not find or load main class.
I tried adding its dependencies by myself in the POM, I get that error and it goes away once I remove them!
I also tried creating a "Spring Starter Project" and choosing dependencies "Web and Thymeleaf" to be added, right after the project is created I see a syntax error in the POM in the test dependency Failure to transfer org.springframework.boot:spring-boot-starter-test:jar
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
and when I remove it and its class, I get the same error above.
here is my POM now:
<?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://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>demo-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>demo-2</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Try to update your maven repository, try first:
mvn dependency:purge-local-repository
Description:
When run on a project, remove the project dependencies from the local
repository, and optionally re-resolve them. Outside of a project,
remove the manually given dependencies.
and then try:
mvn dependency:copy-dependencies
Description:
Goal that copies the project dependencies from the repository to a
defined location.
It seems to me that your local Maven repository doesn't include the thymeleaf dependecy.
The problem was solved after removing failed downloads:
from CMD:
cd %userprofile%\.m2\repository
for /r %i in (*.lastUpdated) do del %i
then updating the project.
It re-downloaded the dependencies and it worked just fine.

Categories

Resources