IntelliJ IDEA 14 Early Preview 发布了

 

图片 1

 

该版本值得关注的修正满含:

Configuring projects

A project in IntelliJ IDEA is a directory that stores your code,
resources you use for developing an application, and configuration files
with your personal workspace settings. Projects can be configured — you
can configure a name, an SDK, specify a language level and a compiler
output.

Projects in IntelliJ IDEA are composed of one or more modules. In a
project with multiple modules, each module can have its own
configuration, and you can run, test and debug each module without
affecting other modules.

If you’re developing a framework-specific application, such as Spring,
you’ll need a facet. Facets come with the IDE, and include libraries, UI
controls and other tools you might need to develop an application for a
specific framework.

IntelliJ IDEA is integrated with build tools, such as Maven or Gradle,
and provides coding assistance for editing the build file, code
completion, inspections and quick-fixes, refactorings, and so on.

Java Debugger:

Working with projects

When you create a new project, you have to select a project type,
configure a JDK, and specify a project name and its location.

If you’re creating a Maven or a Gradle project, you can specify the
necessary settings right in the New
Project wizard, so that when you open your project for the first time,
it will be pre-configured. For example, tasks will be defined, and
dependencies declared.

  • Completely rewritten using the new API, with unified Debugger tool
    window for all languages.

  • The Watches tab now persists expressions (and remembers it even
    after you close it.)

  • Breakpoints can now be arranged by user groups.

  • Hidden elements of long arrays and collections are displayed on
    demand, you no longer need to edit the view settings for that.

Configuring the JDK when creating a project

Some frameworks require their own SDKs in addition to the JDK. For
example, Android or Grails.

To develop applications in IntelliJ IDEA, you need the Java SDK or the
JDK (Java Development Kit).

 

IntelliJ IDEA doesn’t come with the JDK, so if you don’t have the
necessary JDK version, you should download and install it. After that,
you need to let the IDE know in which folder the JDK is installed.

  1. On the New Project wizard, click Download JDK below the Project SDK list. You will be redirected to
    the Oracle official
    website.
  2. Select and download thr necessary JDK version.
  3. Run the Java installation wizard and follow its steps until Java is
    installed.
  4. Once Java is installed, you need to let IntelliJ IDEA know in which
    folder on your computer it resides.

    Click New next to the Project SDK list.

  5. Find and select the folder in which you have installed the JDK (the
    JDK home directory). For example, jdk1.8.0_144.

    On Windows, Java is usually found in C:Program FilesJava. On macOS, you
    can find Java in /System/Library/Java.

 

图片 2You can specify another JDK
version, configure additional SDKs, and change SKD levels any time as
you work with a project. For more information, see Working with
SDKs.

 

Java editor:

Importing a project

To import a project in IntelliJ IDEA, go to File | New | Project from Existing
Sources.

For more information on how to import a project that uses a build tool,
refer
to Maven or Gradle.

If you want to import a project that uses a build tool such as Maven or
Gradle, it’s recommended that you import the associated build file
(pom.xml or build.gradle). In this case, IntelliJ IDEA will
recognize dependencies and artifacts in the project, and will
automatically restore their configuration.

 

In IntelliJ IDEA, you can import a project that come from other external
models. For example, Eclipse, Bnd/Bndtools and Flash Builder.
You can also import a collection of source files to create a new project
from them.

  • Backspace smart indent makes the Backspace key aware of your code
    formatting settings, so it doesn’t break your code when removing
    indents before caret.

  • Now it’s possible to generate tests for methods and add them to an
    existing test class.

Project settings

For projects in IntelliJ IDEA, you can configure a name, specify an SDK,
set a language level and a compiler output. To change project settings,
go to File | Project
Structure or press Ctrl+Shift+Alt+S, and select Project.

图片 3

 

Note the settings you change in this dialog will be applied only to the
project you’re working with at the moment. If necessary, you configure a
global SDK, a language level and a compiler output. It means that these
new global settings will be applied to all newly created projects. To
change the global project settings, go to File | Other Settings | Default Project
Structure | Project.

In IntelliJ IDEA, you can also configure the IDE itself. These settings
include code styles, run configurations, compiler settings, plugins,
inspections, and much more. For more information, refer to Configuring
Project and IDE
Settings.

General IDE:

Project formats

In IntelliJ IDEA, there are two types of projects — the directory-based format and the file-based format format.

If you want to change a project format, you can reimport the
project with
the necessary settings.

The file-based format is a legacy format. It
requires that you place personal workspace settings under version
control. It means that other members of your team may have conflicts on
checkout as they are likely to have different workspace
configuration.

In the directory-based project (default and
recommended), custom settings are stored in a separate file that you do
not have to place under version control. Together with a project,
IntelliJ IDEA creates a module file (.iml) that is needed to keep
dependencies.

If your project uses Maven or Gradle, consider not to place
the .iml file under version control. After you make changes in the
descriptor file (pom.xml in Maven, and build.gradlein Gradle), and
the changes will be imported, IntelliJ IDEA will recreate
the .iml file.

 

  • The new Code cleanup action (available via AnalyzeCode
    Cleanup
    or as an option in the VCS commit dialog) applies
    quick-fixes in batch mode to selected files.

  • The improved Find in path action now can search within files with
    unknown extensions and within the .idea configuration files. It also
    uses indices when searching for strings that contain a part of an
    identifier (3 characters and longer.)

  • Copy/paste selected code as HTML/RTF is now available without
    additional plugins.

  • Better IDE startup time.

Working with modules

In IntelliJ IDEA, a module is an essential part of any project — it is
created automatically together with a project. Projects can contain
multiple modules — you can add new modules, group them, unload modules
you don’t need at the moment.

Modules consist of a content root and a module file. A content root is a
folder where you store your code. Usually, it contains subfolders for
source code, unit tests, resource files, and so on. A module file
(an .iml file) is used for keeping dependencies between files in a
module and dependencies between modules within a project.

JavaFX:

Configuring content roots

The content in IntelliJ IDEA is a group of files that contain your
source code, build scripts, unit tests and documentation. These files
are usually organized in a hierarchy. The top-level folder is called
a content root folder or a content root.

Modules normally have one content root. You can add more content roots.
For example, this might be useful if pieces of your code are stored in
different locations on your computer.

At the same time, modules can exist without content roots. In this case,
you can use them as a collection of dependencies for other modules.

The content root folder in IntelliJ IDEA is marked with
the 图片 4 or 图片 5 icon.

  • SceneBuilder 2.0 is now available as UI designer so you don’t need
    to leave IntelliJ IDEA to work with .fxml files (requires IntelliJ
    IDEA to run on Java 8.)

Adding and removing content roots

To add a new content root:

  1. Navigate to File
    | Project Structure, or press Ctrl+Shift+Alt+S.
  2. Select Modules under the Project Settings section.
  3. Select the necessary module, and then open the Sources tab in the right-hand part of the
    dialog.
  4. Click Add Content Root.
  5. Specify a folder with source files from which you want to create a
    new content root, and click OK.图片 6

To remove a content root:

  1. While on the Sources tab, select the content
    root that you want to remove,
    click 图片 7.
  2. Confirm deletion. Note that corresponding folder won’t be physically
    deleted.

Spring:

Folder categories

 

Folders within content roots can be assigned to several categories.

Similarly to sources, you can specify that your resources are generated.
You can also specify which folder within the output folder your
resources should be copied to.

  • Source
    roots 图片 8

    Production code that should be compiled.

  • Generated source
    roots 图片 9 (sometimes
    marked as [generated])

    These folders are not suggested as target folders when performing
    the Move Classrefactoring and the Create Class from Usage quick fix.

  • Test source
    roots 图片 10

    These folders allow you keep the code related to testing separate
    from the production code. Compilation results for sources and test
    sources, normally, are placed into different folders.

  • Generated test source
    roots 图片 11 (sometimes
    marked as [generated])

    These folders are not suggested as target folders when performing
    the Move Classrefactoring and the Create Class from Usage quick fix.

  • Resource
    roots 图片 12 (available only
    in Java modules)

    Resource files used in your application (images, configuration XML
    and properties files, etc.). During the build process, resource
    files are copied to the output folder as is.

  • Load path
    roots 图片 13 (available only
    when the Ruby plugin is enabled)

    The load path is the path where the require and load statements
    look for files.

  • Test resource
    roots 图片 14 (available only
    in Java modules)

    These folders are for resource files associated with your test
    sources.

  • Excluded
    roots 图片 15

    Files in excluded folders are ignored by code completion, navigation
    and inspection. That is why, when you exclude a folder that you
    don’t need at the moment, you can increase the IDE performance.

    Normally, compilation output folders are marked as excluded.

    Apart from excluding the entire folders, you can also exclude
    specific
    files.

  • Performance when handling Spring projects with large numbers of XML
    descriptor files has been significantly improved.

  • The Select In action now also can navigate to the Spring tool
    window.

  • The new plugin with Spring Websocket support.

Configuring folder categories

To assign a folder to a specific category:

  1. Right-click the necessary folder in the directory tree of the Project tool window.
  2. Select Mark Directory as from the shortcut
    menu.
  3. Select the necessary category.

图片 16

 

This way, you can assign categories to sub-folders as well.

To restore previous category of the folder, right-click this folder
again, select Mark Directory as, and then
select Unmark as <folder category>. For
excluded folders, select Cancel
Exclusion.

You can also configure folder categories in Project Structure | Modules |
Sources.

Grails and Gradle now work better together.

Excluding files

Java files and binaries cannot be excluded.

If you don’t need specific files, but you don’t want to completely
remove them, you can temporary exclude these files from the project.
Excluded files are ignored by code completion, navigation and
inspections.

 

To exclude file, you need to mark it as a plain text text file. You can
always return excluded files to their original state.

  1. Right-click the necessary file in the directory tree of the Project tool window.
  2. Select Mark as
    Plain Text from the menu.

Plain text files are marked with
the 图片 17 icon in the directory
tree.

To revert the changes, right-click the file and select Mark as <file type> from the menu.

Mercurial:

Excluding files and folders by name patterns

In some cases, excluding files or folders one by one is not convenient.
For example, if your source code files and files that are generated
automatically (by a compiler, for instance) are placed in the same
directories, and you want to exclude the generated files only. In this
case, you can configure one or several name patterns for a specific
content root.

All files within excluded folders will be excluded as well.

If a folder name or a file name located inside the selected content root
matches one of the patters, it will be marked as excluded. Objects
outside the selected content root won’t be affected.

 

  1. Navigate to File
    | Project Structure, or press Ctrl+Shift+Alt+S.
  2. Click Modules under the Project Settings section, and then select a module.
    If there’re several content roots in the module, select the one that
    you want to exclude files or folders from.
  3. In the Exclude files field located at the
    bottom of the dialog, enter a pattern. For example, enter *.aj to
    exclude AspectJ files.

    You can configure multiple patters and separate them with
    the ; (semicolon) symbol.

  • The Push dialog has been improved.

  • The Log viewer loads faster.

  • The option to revert uncommitted merge and update from the Log
    viewer
    reverting the current changes.

  • Displaying of the current revision in the Log viewer.

  • Many other enhancements, including the notification about
    incoming/outgoing changes.

Assigning a package prefix to Java sources

In Java, you can assign a package prefix to a folder instead of
configuring a folder structure manually. A package prefix can be
assigned to source folders, generated source folders, test source
folders and generated test source folders.

  1. Press Ctrl+Shift+Alt+S to open the Project
    Structure dialog, and then select Modules.
  2. Select the necessary module, and open the Sources tab.
  3. In the right-hand pane,
    click 图片 18 next to Source Folders or Test Source
    Folders.
  4. Specify the package prefix and click OK.

图片 19

下载地址:

Changing the output path for resources

When you’re building a project, the resources are copied into the
compilation output folder by default. You can specify a different
directory within the output folder to place resources.

  1. Press Ctrl+Shift+Alt+S to open the Project
    Structure dialog.
  2. Select Modules and then select the necessary
    module.
  3. In the right-hand part of the dialog, select the Sources tab.
  4. In the right-hand pane, under Resource
    Folders or Test Resource Folders,
    click 图片 20 to the right of
    the necessary folder (folder path).
  5. Specify the path relative to the output folder root, and click OK.图片 21

(文/开源中黄炎子孙民共和国State of Qatar    

Grouping modules

IntelliJ IDEA allows you to logically group modules. If you have a large
project with multiple modules, grouping will make it easier to navigate
through your project.

To sort out modules, you should give them fully qualified names. Support
for qualified names is enabled by default in IntelliJ IDEA of version
2017.3 and higher, so no further configuration is required. For example,
if you want to group all CDI modules, you can add the cdi. prefix to
their names.

You can use the Flatten Modules shortcut menu
option to view modules on the same level.

图片 22

 

Note that if you’ve configured manual module groups in a project in
IntelliJ IDEA version 2017.2 or lower, you will be able to continue
working with them in version 2017.3, but qualified names won’t be
available.

To enable qualified names, select all modules in the Project tool window, open the shortcut menu and
select Move Module to
Group | Outside Any Group. After that all manually defined modules
groups will be disabled, and you will be able to use qualified names to
group modules.

Working with module dependencies

Modules can depend on SDKs, JAR files (libraries) or other modules
within a project. When you compile or run your code, the list of module
dependencies is used to form the classpath for the compiler or the JVM.

To add a new dependency:

  1. Navigate to File
    | Project Structure or press Ctrl+Shift+Alt+S.
  2. Select Modules |
    Dependencies.
  3. Click 图片 23 or
    press Alt+Insert, and then select a dependency type:

    • JARs or directories.
    • Library. You can select an existing
      library or create a new one and then add it to the list of
      dependencies.
    • Module Dependency.

To remove a dependency, select it and then
click 图片 24 or press Alt+Delete.

Before removing a dependency you can make sure that it is not used in
other modules in the project. To do so, select the necessary dependency
and press Alt+F7. You can also use the Find
Usages option of the shortcut menu.

Specifying dependency scope

Specifying dependency scope allows you control at which step of the
build the dependency should be used.

To configure dependency scope:

  1. Navigate to File
    | Project Structure or press Ctrl+Shift+Alt+S
  2. Select Modules |
    Dependencies.
  3. Select the necessary scope from the list in the Scope column:
    • Compile — the default scope. Compile
      dependencies are needed to build, test, and run a
      project.
    • Test — test dependencies are needed to
      compile and run unit tests.
    • Runtime — runtime dependencies are a part
      of the classpath to test and run a project.
    • Provided — the dependency is used for
      building and testing a project.

IntelliJ IDEA processes dependencies for test sources differently from
other build tools (e.g. Gradle and Maven). If your module (say, module
A) depends on another module (module B), IntelliJ IDEA assumes that the
test sources in A depend not only on the sources in B but also on its
own test sources. Consequently, the test sources of B are also included
in the corresponding classpaths.

Sorting dependencies

The order of dependencies is important as IntelliJ IDEA will process
them in the same order as they are specified in the list.

During compilation, the order of dependencies defines the order in which
the compiler (javac) looks for the classes to resolve the corresponding
references. At runtime, this list defines the order in which the JVM
searches for the classes.

You can sort the dependencies by their names and scopes. You can also
use
the 图片 25 and 图片 26buttons
to move the items up and down in the list.

Analyzing dependencies

If you want to check whether a dependency still exists in your project,
and find its exact usages, you can run dependency analysis:

  1. Navigate to File
    | Project Structure or press Ctrl+Shift+Alt+S.
  2. Select Modules |
    Dependencies.
  3. Right-click the necessary dependency and select Analyze This Dependency.

IntelliJ IDEA will show you collected dependency usages in the Dependency Viewer tool window. You can analyze several
dependencies one by one without closing the dialog. The result of each
analysis will be open in a separate tab of the tool window. After you
analyze all necessary dependencies, you can close the Project Structure dialog and view results of each
dependency analysis.

If IntelliJ IDEA finds no dependency usages in the project, you will be
prompted to remove this dependency.

Adding support for frameworks and technologies

For developing framework-specific applications, IntelliJ IDEA features
facets.

A facet is a set of tools that are specific for a particular framework
or a technology. Facets can include libraries, coding assistance
features, artifact configurations, UI controls that are essential for
the framework you are working with, and much more. The exact set of
features depends on each facet.

Adding a facet to a module

IntelliJ IDEA can identify a file or a directory that is typical for a
certain framework, and add a the necessary facet for you. Once a
framework is detected and added, IntelliJ IDEA will inform you about
missing configuration and will suggest necessary actions. For example,
to configure facet settings.

You can add more than one facet to one module.

If a facet is not detected automatically, you can add it manually:

 

  1. Navigate to File
    | Project Structure, or press Ctrl+Shift+Alt+S, and click Facets.
  2. Click 图片 27 (or
    press Alt+Insert) and select a framework from the list.
  3. Select a module to which you want to add a facet and configure the
    facet, if required.

You can also add a facet as you create a new project or a new module.

Excluding frameworks from auto-detection

By default, auto-detection is enabled for all the supported frameworks.
You can disable framework auto-detection completely, or exclude
individual frameworks from auto-detection.

  1. Open the Project Structure dialog,
    select Facets, and then select Detection.
  2. Click 图片 28 (or
    press Alt+Insert), then select the necessary option. For example,
    you can disable auto-detection of all frameworks in one directory
    only.
  3. Deselect the Enable framework
    detection checkbox to disable auto-detection of all frameworks in
    the entire project.

Unloading modules

To make the IDE work faster, you can temporary set aside or unload
modules that you don’t need at the moment. IntelliJ IDEA ignores the
unloaded modules when you search through or refactor your code, or
compile your project.

When you unload modules, you do it locally — the information about
unloaded modules is not shared through version control.

To unload or load modules:

  1. In the Project tool window, right-click a
    module, and select Load/Unload
    Modules.
  2. Use the buttons in the middle section of the dialog to manage
    modules. You can also double-click a module in the dialog to load or
    unload it.图片 29

Troubleshooting

If modules in your project depend on each other, you may face errors
when you unload one or more of them.

For example, if Module 1 depends on Module 2, and you unload Module 2,
IntelliJ IDEA won’t be able to resolve references to classes in Module

  1. Moreover, compilation of Module 1 will probably fail.

To avoid such errors, the IDE analyzes dependencies when you load or
unload modules. When you load modules, IntelliJ IDEA will suggest to
load all dependencies as well. When you unload modules, the IDE will
find all dependent modules and will unload them, too.

图片 30

 

If you unload Module 1, you may not see any errors in code in Module 2,
and you will also be able to compile Module 2. However, you may
accidentally break compilation of dependant code in Module 1 by making
changes in code in Module 2. Since Module 1 is unloaded, you won’t be
able to see any errors until you load it back and compile.

If you invoke Find Usages or refactoring on a class, field, method, etc.
contained in Module 2, the result may be incomplete because the contents
of Module 1 are not taken into account. IntelliJ IDEA will inform you
about that.

Moreover, the IDE will compile unloaded modules every time you commit
changes, and will check that the changes don’t affect unloaded modules.
See more information inCommitting changes with unloaded
modules.

图片 31

 

Automatically loading and unloading new modules

If your teammates add new modules to the project, you will download them
to your computer on the project update. After that, the IDE will analyze
dependencies between all modules in the updated project.

If you have unloaded modules, IntelliJ IDEA will load or unload new
modules according to the results of the dependency analysis.

If new modules depend on the existing unloaded modules, the new modules
will be marked as unloaded. IntelliJ IDEA will ignore them because
otherwise you may face errors when you try to compile them. 

图片 32

 

If existing loaded modules have direct dependencies on new modules, the
new modules will be marked as loaded. 

图片 33

 

If existing loaded modules have no dependencies on the newly added
modules, the new modules will be marked as unloaded. You can manually
mark them as loaded as soon as you need them. 

图片 34

 

Committing changes with unloaded modules

If you have unloaded modules, and you make changes in files that your
unloaded modules depend on, compilation of these modules may fail after
you load them back.

To avoid compilation failures of unloaded modules, make sure that
the Compile affected unloaded modules option is
selected in the Commit
Changes dialog.

Before committing changed files, IntelliJ IDEA will compile unloaded
modules to make sure that the changes don’t affect these modules. The
IDE will inform you about the detected errors, and will suggest
resolving them before the commit.

Working with SDKs

To develop applications in IntelliJ IDEA, you need the Java SDK (JDK).

A Software Development Kit, or an SDK, is a collection of tools that you need to develop
an application for a specific software framework. For example, for
Android applications, you will need the Android SDK.

 

 

  • Java SE Developments Kits
    (JDKs)
  • Java Micro Edition (ME)
    SDKs
  • Android SDKs
  • Flex and AIR
    SDKs
  • Python SDKs
  • Ruby SDKs
  • Google App Engine
    SDK
  • IntelliJ Platform Plugin SDKs (for developing IntelliJ IDEA plugins)

 

SKDs contain binaries, source code for the binaries, and documentation
for the source code. For Java, SDKs also contain annotations.

 

SDK levels

SDKs can be configured at all three levels:

Global — used by multiple projects. Generally,
SDKs are global; after you define an SDK for the first IntelliJ IDEA
project, it will be suggested as a default SDK for all project that you
will create afterwards.

Project — used by all modules within a project.
For example, this might be useful if you want to compile a project with
a specific SDK version.

Module — used by a specific module.

Defining SDKs

To define an SDK means to let IntelliJ IDEA know in which folder on your
computer the necessary SDK version is installed. This folder is called
SDK home directory.

Managing global SDKs

To manage the list of global SDKs available for
your projects:

  1. Navigate to File
    | Project Structure.
  2. Select SDKs under the Platform Settings section.
  3. To add a new SDK or a new SDK version,
    click 图片 35 (or
    press Alt+Enter), select an SDK type and specify its installation
    directory.
  4. To remove an SDK, select it in the list and
    click 图片 36 (or
    press Alt+Delete).

图片 37

Changing project SDK

To change the project SDK:

  1. Navigate to File
    | Project Structure.
  2. Select Project under the Project Settings section.
  3. From the Project SDK list, select another SDK
    or SDK version.
    If the necessary SDK is not defined in IntelliJ IDEA yet,
    click New and specify its installation
    folder.

Note that after you change the project SDK, all modules within this
project will inherit this new SDK.

图片 38

 

Changing module SDK

To change the module SDK:

  1. Navigate to File
    | Project Structure.
  2. Select Modules under the Project Settings section.
  3. Select the necessary module, and click Dependencies.
  4. From the Module SDK list, select another SDK
    or SDK version you want to use.
    If the necessary SDK is not defined in IntelliJ IDEA yet,
    click New and specify its installation
    folder.

图片 39

 

Last modified: 22 December 2017