Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build maven imported project in Intellij IDEA 11?

I have created a new IntelliJ project by importing the maven projects. Which worked fine: enter image description here

I can execute the maven goals from the Maven Projects pane (on the left side of the IDE screen). For instance, I can compile the projects just fine using the compile goal.

Now I want to build the project from the UI using the Build|Make Project option. However, it does not work. It complains about the missing application packages as if it does not see the dependencies. These dependencies are defined in the respective pom.xml files, but making the project from the IDE seems to ignore it.

What do I have to do to make it work?

EDIT

OK, I have deleted the .m2 directory from my home and started the compile goal from the Maven Projects flyout. I can see in the console pane that maven downloads dependencies from the Maven Central (I am giving just first few lines of the log, it is quite long):

"C:\Program Files (x86)\Java\jdk1.6.0_29\bin\java" -Dclassworlds.conf=O:\java\apache-maven-3.0.4\bin\m2.conf -Dmaven.home=O:\java\apache-maven-3.0.4 -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.2\bin" -Dfile.encoding=UTF-8 -classpath "O:\java\apache-maven-3.0.4\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 11.1.2\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher --no-plugin-registry --fail-fast --strict-checksums --update-snapshots -f C:\dev\shunra\Application\Builder\build\vcat\pom.xml compile
[WARNING] Command line option -npr is deprecated and will be removed in future Maven versions.
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.shunra:VCat-build:pom:1.0.0.SNAPSHOT
[WARNING] 'version' uses an unsupported snapshot version format, should be '*-SNAPSHOT' instead. @ line 7, column 11
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] util.logging
[INFO] Infra
[INFO] dtos
[INFO] commons
[INFO] license
[INFO] core
[INFO] vcat
[INFO] VCat-build
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building util.logging 0.0.1
[INFO] ------------------------------------------------------------------------
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.pom (7 KB at 7.2 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/19/maven-plugins-19.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/19/maven-plugins-19.pom (11 KB at 38.7 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/19/maven-parent-19.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/19/maven-parent-19.pom (25 KB at 70.0 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/9/apache-9.pom (15 KB at 63.5 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.5/maven-resources-plugin-2.5.jar (26 KB at 63.1 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/2.3.2/maven-compiler-plugin-2.3.2.pom (8 KB at 29.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/18/maven-plugins-18.pom (13 KB at 53.6 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/16/maven-parent-16.pom (23 KB at 66.8 KB/sec)
Downloading: http://repo.maven.apache.org/maven2/org/apache/apache/7/apache-7.pom
Downloaded: http://repo.maven.apache.org/maven2/org/apache/apache/7/apache-7.pom (15 KB at 59.5 KB/sec)

So, I suppose there is no problem connecting to the Maven Central.

EDIT2

Please, observe: enter image description here Notice the problem - there are two modules imported from Maven - Common and Core. Their Maven artifact Id are commons and core respectively. IntelliJ seems to confuse between the artifact Id and module name, because:

  1. The Project flyout displays the module name followed by the respective maven artifact Id in parentheses.
  2. In the Project settings dialog the modules are given by the respective maven artifact Id only.
  3. But in the module dependencies it lists the module name only.

The Core module (maven artifact Id core) should see the dependency Common module (maven artifact Id commons), but it does not and this is the problem.

EDIT3

Here is the topmost 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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.shunra</groupId>
    <name>VCat-build</name>
    <version>1.0.0.SNAPSHOT</version>
    <artifactId>VCat-build</artifactId>
    <packaging>pom</packaging>
    <modules>
        <module>../../../util.logging</module>
        <module>../../../Infra</module>
        <module>../../../DTOs</module>
        <module>../../../ShunraLicense</module>
        <module>../../../Common</module>
        <module>../../../Core</module>
        <module>../../../VCat</module>
    </modules>
    <build>
        <plugins>
        </plugins>
    </build>
</project>

Here is the one for the Common module:

<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.shunra</groupId>
  <artifactId>commons</artifactId>
  <version>0.0.1</version>
  <dependencies>
        <dependency>
            <groupId>com.sun.jna</groupId>
            <artifactId>jna</artifactId>
            <version>3.0.9</version>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-math</artifactId>
            <version>2.2</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>1.9.4</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.2.7</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
                <groupId>com.shunra</groupId>
                <artifactId>util.logging</artifactId>
                <version>0.0.1</version>
        </dependency>
        <dependency>
                <groupId>com.google.code.gson</groupId>
                <artifactId>gson</artifactId>
                <version>1.6</version>
                <scope>compile</scope>
        </dependency>
        <dependency>
                <groupId>commons-codec</groupId>
                <artifactId>commons-codec</artifactId>
                <version>1.6</version>
                <scope>compile</scope>
        </dependency>
        <dependency>
              <groupId>org.restlet.jse</groupId>
              <artifactId>org.restlet</artifactId>
              <version>2.0.10</version>
        </dependency>
        <dependency>
          <groupId>javax.inject</groupId>
          <artifactId>javax.inject</artifactId>
          <version>1</version>
          <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-configuration</groupId>
            <artifactId>commons-configuration</artifactId>
            <version>1.8</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>commons-beanutils</groupId>
            <artifactId>commons-beanutils</artifactId>
            <version>1.8.3</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
<!--        <dependency>
            <groupId>com.shunra</groupId>
            <artifactId>license</artifactId>
            <version>0.0.1</version>
        </dependency> -->
        <dependency>
              <groupId>com.shunra</groupId>
              <artifactId>dtos</artifactId>
              <version>0.0.1</version>
        </dependency>
  </dependencies>
    <repositories>
    <repository>
       <id>maven-restlet</id>
       <name>Public online Restlet repository</name>
       <url>http://maven.restlet.org</url>
    </repository> 
   </repositories>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source/>
          <target/>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

And here is the one for the Core module:

<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.shunra</groupId>
  <artifactId>core</artifactId>
  <version>0.0.1</version>
  <dependencies>
    <dependency>
      <groupId>com.shunra</groupId>
      <artifactId>commons</artifactId>
      <version>0.0.1</version>
    </dependency>
    <dependency>
        <groupId>com.shunra</groupId>
        <artifactId>license</artifactId>
        <version>0.0.1</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <source/>
          <target/>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

EDIT4

Finally solved it. Removed all the Intellij files and reimported again. I guess the pom.xml files have changed in a way confusing to IntelliJ.

like image 397
mark Avatar asked Jan 08 '13 12:01

mark


1 Answers

Looking at the screenshot, you don't appear to working offline which is the most common cause of this problem.

  1. Try downloading sources and documentation from the Maven Projects flyout (it's the third icon in from the left). This often has the effect of waking it up and causing a download.

  2. Perform a manual Maven build using the Runtime configuration. Select Edit Configurations | Maven then ensure your working directory is your project root, and select a goal of "clean package". This will force Intellij to rebuild directly through Maven which may wake up the internal background build process.

  3. Check your settings and ensure that Intellj's Maven has correctly read the repository information from the POM and is able to locate Maven Central. You may have a problem with your local settings.xml that is preventing download.

  4. You could also remove the .idea and .iml files to force a project re-import.

  5. Restart Intellij and hope for the best...

  6. As a last resort, invalidate your caches through File | Invalidate Caches. This might slow your development down a bit until they are rebuilt through use.

Edit to cover updated question

It appears that your POM files are in a bit of a mess. They don't follow the standard Maven directory layout and as a result Intellij may be getting confused between your directory names and the internal artifactId entries. Often the parent POM (containing the modules) is placed in the root of the project, and modules form a directory hierarchy below.

With some extensive settings configuration you could coerce Intellij into working with the existing structure, but a better solution would be renaming the directories to match the artifactIds and moving the modules around so that they form a Maven reactor project.

Further edit in light of comment

Seems that it was the Intellij project synchronization. Deleting the .idea directory and .iml files did the trick. I've updated the list accordingly.

like image 188
Gary Rowe Avatar answered Oct 19 '22 00:10

Gary Rowe