11

I have maven project. Maven build complete SUCCESS. But i can't make this project.

[INFO] BUILD SUCCESS

Project contains one module. Idea can't see dependencies.

Error:(3, 38) java: D:\Dropbox\Programming\java\spring\springBook\src\main\java\ch14\validator\ContactTestValidator.java:3: 
package org.springframework.stereotype does not exist

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>springBook</groupId>
<artifactId>springBook</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- Shared version number properties -->
<properties>
    <org.springframework.version>3.2.3.RELEASE</org.springframework.version>
</properties>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <!--для валидации бинов необходима-->
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.5.6</version>
    </dependency>
    <dependency>
        <!--Spring Data JPA использует его - добавим и пользуемся-->
        <!--API для работы с датами-->
        <!--ch14 validator-->
        <groupId>joda-time</groupId>
        <artifactId>joda-time</artifactId>
        <version>2.0</version>
    </dependency>
    <dependency>
        <!--ch14 validator-->
        <!--API интерфейса JSR-303-->
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>1.0.0.GA</version>
    </dependency>
    <dependency>
        <!--ch14 validator-->
        <!--API, которая поддерживает интерфейс JSR-303 - BeanValidation-->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.2.GA</version>
    </dependency>
    <dependency>
        <!--для валидации. (@Type...)-->
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.5.6-Final</version>
    </dependency>
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2.2</version>
    </dependency>
    <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.6.2</version>
    </dependency>
    <!--Spring framework-->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>${org.springframework.version}</version>
    </dependency>
</dependencies>
<build>
    <finalName>springBook</finalName>
</build>
</project>

Could you help me? Unfortunately, I can't add screenshots.. There are screenshots: http://screencast.com/t/iNaWO9gy http://screencast.com/t/iBGTyMpgH

Project settings - Libraries - empty;

reimport didn't help;

Adam
  • 5,215
  • 5
  • 51
  • 90
yazabara
  • 1,253
  • 4
  • 21
  • 39
  • Did you add the pom.xml to your maven projects in IntelliJ? If you did that you shouldnt see empty libraries since they should contain your .jar depentencies – zpontikas Apr 09 '14 at 08:01
  • 2
    Have you tried opening the `Maven project` tool window and click on the `Reimport all maven projects` button? – Morfic Apr 09 '14 at 08:03
  • file->invalidate casches/restart – RMachnik Apr 09 '14 at 08:06
  • Did you set the maven environment variable or did you set maven in the IDE settings? If not, Intellij will not find maven and sometimes screw thins up... – morpheus05 Aug 11 '14 at 19:25

8 Answers8

37

Do the following steps:

  1. Find your pom.xml in your files
  2. Right click on it --> Maven --> Import
  3. Wait for the project to load :D
  4. Press ctrl+alt+shift+s (This opens the Projects window.)
  5. Go to libraries and see if they are empty (they shouldnt)
  6. If they are post your full pom.xml please so I can see the problem
  7. If you still have a problem got to File --> Invalidate Caches /Restart
  8. Go to maven and Reimport All Maven Projects
Matthew Taylor
  • 13,365
  • 3
  • 17
  • 44
zpontikas
  • 5,445
  • 2
  • 37
  • 41
6

Option Maven -> Reimport should force Intellij to reload all dependencies. Alternatively, as mentioned in comments you can click the Reimport All Maven Projects button in Maven Projects view.

Blekit
  • 663
  • 4
  • 7
3

In my case, I had my own apache-maven-3.5.2 folder and a misconfiguration created my problem. Maybe it's your case too:

In rush, I set the local repository to C:/my/folder/apache-maven-3.5.2/settings.xml, but it must be a folder so Maven didn't allow me to download the dependencies. Then I changed the default (in the picture) and it worked.

enter image description here

Lucas Amorim Silva
  • 567
  • 1
  • 7
  • 14
1

Open the module dependencies (press F12 on the module), go to Modules -> Dependencies and make sure maven imports are part of the of this.

David
  • 19,577
  • 28
  • 108
  • 128
  • This is the problem, you're missing your maven dependencies, click the green tick on the right and add the maven dependencies as a dependency of this module. – David Apr 09 '14 at 08:55
1

Try to import the project from sources, if this answer didn't help you.

Community
  • 1
  • 1
naXa stands with Ukraine
  • 35,493
  • 19
  • 190
  • 259
1

The following worked for me.

  1. Deleted the maven dependency from my local repository
  2. mvn clean install downloaded the dependency again
  3. File --> Invalidate Caches/Restart
  4. I still saw the compilation error
  5. on my mac, I hit option + enter, intellij asked me to add the jar to classpath
  6. build -> make project
datta
  • 521
  • 2
  • 5
  • 16
1

I had faced the same problem, and the issue was small. I had changed the location of settings.xml file of maven and Intellij was picking up the default from C:\users\.m2\settings.xml

So point your maven settings.xml to the correct file as below: File--> Settings--> Build, Execution, Deployment--> Maven then on the right window, override "User settings file" to the settings.xml where you have in your local disk.

If you have installed maven in a non-default location then this file you can find in: \apache-maven-3.2.3\conf\settings.xml

Hamid
  • 717
  • 7
  • 15
1

Right click on pom.xml and click Add as Maven Project

swade
  • 668
  • 2
  • 7
  • 15