IntelliJ IDEAprojectmanagement

MasterIntelliJ IDEA projectmanagementfunctions, includingprojectstructureconfiguration, modulemanagement, 依赖management, 构建configurationetc.

1. projectstructureconfiguration

projectstructureconfiguration is IntelliJ IDEAprojectmanagement core, 它定义了project basicproperty, SDK, modulestructure, 依赖relationshipsetc..

1.1 打开projectstructureconfiguration

要打开projectstructureconfiguration, 请按照以 under 步骤operation:

  1. 点击File > Project Structure
  2. or using fast 捷键Ctrl + Alt + Shift + S

1.2 project设置

in Project选项卡in, 你可以configuration以 under project级别 设置:

  • Project SDK: 选择projectusing SDK
  • Project language level: 设置project language级别
  • Project compiler output: 设置project编译输出Table of Contents

1.3 module设置

in Modules选项卡in, 你可以configurationproject modulestructure, including:

  • 添加, delete and renamemodule
  • configurationmodule sourcescodeTable of Contents, testTable of Contents and resourceTable of Contents
  • 设置module 依赖relationships
  • configurationmodule 编译输出Table of Contents

1.4 依赖设置

in Libraries选项卡in, 你可以managementproject 依赖library, including:

  • 添加, delete and update依赖library
  • configuration依赖library 作用范围
  • 解决依赖conflict

2. modulemanagement

module is IntelliJ IDEAproject basic组成单位, 一个project可以package含 many 个module.

2.1 creationmodule

要creation一个 new module, 请按照以 under 步骤operation:

  1. 打开projectstructureconfiguration (Ctrl + Alt + Shift + S)
  2. 选择Modules选项卡
  3. 点击"+"按钮, 选择"New Module"
  4. 选择moduleclass型, such as"Java"
  5. configurationmoduleSDK and other选项
  6. 点击"Next"
  7. 输入module名称 and 位置
  8. 点击"Finish"

2.2 configurationmodule

要configurationmodule property, 请按照以 under 步骤operation:

  1. 打开projectstructureconfiguration (Ctrl + Alt + Shift + S)
  2. 选择Modules选项卡
  3. 选择要configuration module
  4. in right 侧面板in, 你可以configuration:
    • Sources: configurationsourcescodeTable of Contents, testTable of Contents and resourceTable of Contents
    • Dependencies: configurationmodule 依赖relationships
    • Paths: configurationmodule 编译输出Table of Contents
    • Compiler: configurationmodule 编译选项
  5. 点击"Apply" and "OK"保存设置

2.3 deletemodule

要deletemodule, 请按照以 under 步骤operation:

  1. 打开projectstructureconfiguration (Ctrl + Alt + Shift + S)
  2. 选择Modules选项卡
  3. 选择要delete module
  4. 点击"-"按钮
  5. in 确认 for 话框in, 点击"Remove"

提示

deletemodule只会 from projectin移除module 引用, 不会deletemodule practicalfile. such as果要deletemodulefile, 需要手动deletefilesystemin 相应Table of Contents.

3. 依赖management

依赖management is projectmanagement important 组成部分, 它负责managementproject所需 out 部library and module依赖.

3.1 添加依赖

要 for module添加依赖, 请按照以 under 步骤operation:

  1. 打开projectstructureconfiguration (Ctrl + Alt + Shift + S)
  2. 选择Modules选项卡
  3. 选择要添加依赖 module
  4. 选择Dependencies选项卡
  5. 点击"+"按钮, 选择依赖class型:
    • JARs or directories: 添加本地JARfile or Table of Contents
    • Library: 添加已configuration library
    • Module Dependency: 添加othermoduleserving as依赖
    • Module SDK: 添加moduleSDKserving as依赖
  6. 根据选择 依赖class型, configuration依赖详情
  7. 点击"Apply" and "OK"保存设置

3.2 configuration依赖范围

依赖范围定义了依赖 in project构建过程in 可见性 and availability. common 依赖范围including:

  • Compile: 默认范围, 依赖 in 编译, test and run时都可用
  • Test: 依赖仅 in test时可用, 编译 and run时不可用
  • Provided: 依赖 in 编译 and test时可用, run时由containers or environmentproviding
  • Runtime: 依赖 in test and run时可用, 编译时不可用
  • System: 依赖 in 编译, test and run时都可用, 但需要显式指定path

3.3 解决依赖conflict

当projectin存 in many 个version 同一依赖时, 就会发生依赖conflict. IntelliJ IDEAproviding了依赖analysistool, 可以helping你识别 and 解决依赖conflict.

要查看依赖tree并解决conflict, 请按照以 under 步骤operation:

  1. 打开projectstructureconfiguration (Ctrl + Alt + Shift + S)
  2. 选择Modules选项卡
  3. 选择要analysis依赖 module
  4. 选择Dependencies选项卡
  5. 点击"analysis Dependencies"按钮
  6. in 依赖treein, 你可以查看所 has 依赖及其传递依赖
  7. for 于conflict 依赖, 你可以选择要using version

4. 构建configuration

IntelliJ IDEAsupport many 种构建tool, such asMaven, Gradle, Antetc..

4.1 Mavenconfiguration

such as果你 projectusingMaven构建tool, IntelliJ IDEA会automatically detect并importMavenconfiguration. 你可以 in Settings/PreferencesinconfigurationMaven选项:

  1. 点击File > Settings (Windows/Linux) or IntelliJ IDEA > Preferences (macOS)
  2. 选择build, Execution, deploymentment > build Tools > Maven
  3. configurationMaven home directory, User settings file, Local repositoryetc.选项
  4. 点击"Apply" and "OK"保存设置

4.2 Gradleconfiguration

such as果你 projectusingGradle构建tool, IntelliJ IDEA会automatically detect并importGradleconfiguration. 你可以 in Settings/PreferencesinconfigurationGradle选项:

  1. 点击File > Settings (Windows/Linux) or IntelliJ IDEA > Preferences (macOS)
  2. 选择build, Execution, deploymentment > build Tools > Gradle
  3. configurationGradle home, Gradle JVM, build and run using, Run tests usingetc.选项
  4. 点击"Apply" and "OK"保存设置

4.3 构建project

要构建project, 请using以 under method之一:

  • 点击build > build Project
  • or using fast 捷键Ctrl + F9
  • for 于Mavenproject, 你可以usingMaventool窗口run构建commands
  • for 于Gradleproject, 你可以usingGradletool窗口run构建task

5. run/debugconfiguration

run/debugconfiguration定义了such as何run and debugproject.

5.1 creationrun/debugconfiguration

要creationrun/debugconfiguration, 请按照以 under 步骤operation:

  1. 点击Run > Edit Configurations
  2. 点击"+"按钮, 选择configurationclass型, such as"Application", "JUnit", "Maven", "Gradle"etc.
  3. configurationrun/debug选项, such as主class, 工作Table of Contents, VM选项, 程序parameteretc.
  4. 点击"Apply" and "OK"保存configuration

5.2 managementrun/debugconfiguration

in Run/Debug Configurations for 话框in, 你可以:

  • creation new run/debugconfiguration
  • 编辑现 has configuration
  • copy and deleteconfiguration
  • 设置默认configuration
  • import and exportconfiguration

5.3 run and debug

要run or debugproject, 请using以 under method之一:

  • usingtool栏 on run/debug按钮
  • using fast 捷键Shift + F10run, Shift + F9debug
  • in 编辑器in right 键点击主class, 选择"Run" or "Debug"

6. project共享 and 协作

IntelliJ IDEAproviding了 many 种方式来共享 and 协作Developmentproject.

6.1 usingversion控制system

IntelliJ IDEA in 置了 for Git, SVN, Mercurialetc.version控制system support. 你可以through以 under 步骤初始化 or importversion控制system:

  1. 点击VCS > Enable Version Control Integration
  2. 选择version控制systemclass型, such as"Git"
  3. 点击"OK"

6.2 exportproject设置

要exportproject设置, 以便 in other计算机 on import, 请按照以 under 步骤operation:

  1. 点击File > Export Settings
  2. 选择要export 设置选项
  3. 选择exportfile位置
  4. 点击"OK"

6.3 importproject设置

要import之 before export project设置, 请按照以 under 步骤operation:

  1. 点击File > Import Settings
  2. 选择export 设置file
  3. 点击"OK"
  4. 选择要import 设置选项
  5. 点击"OK"

实践练习

请按照以 under 步骤completion练习:

  1. creation一个 new Javaproject, 命名 for "MultiModuleProject"
  2. in projectincreation两个module: "core" and "app"
  3. in "core"moduleincreation一个 simple toolclass
  4. in "app"modulein添加 for "core"module 依赖
  5. in "app"moduleincreation一个主class, using"core"modulein toolclass
  6. configurationrun/debugconfiguration, run"app"module
  7. 尝试usingMaven or Gradle构建project