我通过导入 maven 项目创建了一个新的 IntelliJ 项目。效果很好:
我可以从 Maven 项目窗格(在 IDE 屏幕的左侧)执行 Maven 目标。例如,我可以使用 compile 目标很好地编译项目。
现在我想使用Build|Make Project选项从 UI 构建项目。但是,它不起作用。它抱怨缺少应用程序包,就好像它没有看到依赖项一样。这些依赖项在各自的 pom.xml 文件中定义,但从 IDE 制作项目似乎忽略了它。
我必须做些什么才能让它发挥作用?
编辑
好的,我已经从我的家中删除了.m2目录,并从 Maven 项目弹出窗口启动了编译目标。我可以在控制台窗格中看到 maven 从 Maven Central 下载依赖项(我只给出了日志的前几行,它很长):
"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)
所以,我想连接到 Maven 中心没有问题。
编辑2
请注意:
注意问题 - 从 Maven 导入了两个模块 - Common和Core。他们的 Maven 工件 ID 分别是commons和core。IntelliJ 似乎混淆了工件 ID 和模块名称,因为:
- 项目弹出显示模块名称,后跟括号中的相应 maven 工件 ID。
- 在项目设置对话框中,模块仅由各自的 Maven 工件 ID 给出。
- 但在模块依赖项中,它仅列出模块名称。
核心模块(maven artifact Id core)应该看到依赖Common模块(maven artifact Id commons),但它没有,这就是问题所在。
编辑3
这是最顶层的 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>
这是通用模块的一个:
<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>
这是核心模块的一个:
<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>
编辑4
终于解决了。删除所有 Intellij 文件并再次重新导入。我猜 pom.xml 文件已经以一种让 IntelliJ 感到困惑的方式发生了变化。