der*_*rek 8 intellij-idea maven
每次创建Maven项目时,都会有一个.iml文件和一个pom.xml文件.他们的关系究竟是什么?
nay*_*kam 11
IntelliJ 的想法并不理解maven 项目模式l (POM.xml) 本身。在idea中创建或导入maven项目时。它还创建自己的项目结构、maven 依赖项、模块详细信息等。基本上需要项目元数据的格式,它可以理解并在内部使用它进行操作。这些元数据存储在.iml文件和.idea项目目录中。
保持其自身结构的主要优势将提供更快运行和有效管理项目的能力。我希望这对这两个文件之间的关系给出一些解释。
示例 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>2.5.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock</artifactId>
<version>${jmock.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jmock</groupId>
<artifactId>jmock-junit4</artifactId>
<version>${jmock.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junitperf</groupId>
<artifactId>junitperf</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
<properties>
<jmock.version>2.5.1</jmock.version>
<junit.version>4.6</junit.version>
<log4j.version>1.2.14</log4j.version>
<org.slf4j.version>1.5.2</org.slf4j.version>
</properties>
</project>
Run Code Online (Sandbox Code Playgroud)
相关的 IDEA .iml 文件
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: log4j:log4j:1.2.14" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-log4j12:1.5.2" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.5.2" level="project" />
<orderEntry type="library" name="Maven: org.easymock:easymock:2.5.2" level="project" />
<orderEntry type="library" name="Maven: org.jmock:jmock:2.5.1" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-library:1.1" level="project" />
<orderEntry type="library" name="Maven: org.jmock:jmock-junit4:2.5.1" level="project" />
<orderEntry type="library" name="Maven: junit:junit-dep:4.4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.6" level="project" />
<orderEntry type="library" name="Maven: junitperf:junitperf:1.8" level="project" />
</component>
</module>
Run Code Online (Sandbox Code Playgroud)
The pom.xml is used by maven to resolve your project's dependencies, which plugins to execute and a lot of other things. From the maven website:
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project.
The .iml file on the other hand is part of IntelliJ's own project structure. The short version is that it declares the libraries (e.g. jars) that are visible only to the module, and not the rest of the project or other projects. It's an xml file containing a library entry for each artifact declared in your pom.xml, along with its scope (e.g. TEST or COMPILE). For example:
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="COMPILE" name="Maven: com.google.guava:guava:18.0" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-library:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
</component>
</module>
Run Code Online (Sandbox Code Playgroud)
I assume IntelliJ keeps its own file format so it can read the project faster, regardless of which build system the project is using (e.g. maven vs. gradle).
| 归档时间: |
|
| 查看次数: |
9905 次 |
| 最近记录: |