The Duplicates Finder (Java) Build Runner is intended for catching similar code fragments and providing a report on discovered repetitive blocks of Java code. This runner is based on IntelliJ IDEA capabilities, so an IntelliJ IDEA project file (.ipr) or directory (.idea) is required to configure the runner. Since TeamCity 2017.1, in addition to the bundled version, it is possible to install another version of JetBrains IntelliJ Inspections and Duplicates Engine and/or change the defaults using the Administration | Tools page.
The Duplicates Finder (Java) can also find Java duplicates in projects built by Maven2 or above.
In order to run inspections for your project you should have either an IntelliJ IDEA project file (.ipr)/project directory (.idea), or Maven2 or above pom.xml of your project checked into your version control.
This page contains reference information about the following Duplicates Finder (Java) Build Runner fields:
Project file type
To be able to run IntelliJ IDEA inspections on your code, TeamCity requires either an IntelliJ IDEA project file\directory, Maven pom.xml or Gradle build.gradle to be specified here.
Path to the project
Depending on the type of project selected in the Project file type, specify here:
Detect global libraries and module-based JDK in the *.iml files
This option is available if you use an IntelliJ IDEA project. In IntelliJ IDEA, the module settings are stored in *.iml files, thus, if this option is checked, all the module files will be automatically scanned for references to the global libraries and module JDKs when saved. This helps ensure that all references will be properly resolved.
This option is available if you use an IntelliJ IDEA project. Click this button to reparse your IntelliJ IDEA project and import the build settings right from the project, for example the list of JDKs.
This section is displayed, when an IntelliJ IDEA module file (.iml) referenced from an IPR-file:
To refresh values in this section click Check/Reparse Project.
This field appears if the project file contains path macros, defined in the Path Variables dialog of IntelliJ IDEA's Settings dialog. In Set value to field, specify a path to the project resources to be used on different build agents.
This section provides the list of JDKs detected in the project.
Use this field to specify the JDK home for the project.
JDK Jar File Patterns
Click this link to open a text area where you can define templates for the jar files of the project JDK. Use Ant rules to define the jar file patterns.
For Mac OS X, use the following lines:
If your project uses the IDEA JDK, specify the location of the IDEA home directory
IDEA Jar Files Patterns
Click this link to open a text area, where you can define templates for the jar files of the IDEA JDK.
You can use references to external properties when defining the values, like
If this option is checked, the test sources will be included in the duplicates analysis.
Include / exclude patterns| Optional, specify to restrict the sources scope to run duplicates analysis on. For details, refer to the section below| #IdeaPatterns]|
Use these options to define which elements of the source code should be distinguished when searching for repetitive code fragments. Code fragments can be considered duplicated if they are structurally similar, but contain different variables, fields, methods, types or literals. Refer to the samples below:
If this option is checked, the similar contents with different variable names will be recognized as different. If this option is not checked, such contents will be recognized as duplicated:
If this option is checked, the similar contents with different field names will be recognized as different. If this option is not checked, such contents will be recognized as duplicated:
If this option is checked, the methods of similar structure will be recognized as different. If this option is not checked, such methods will be recognized as duplicated. In this case, they can be extracted and reused.
If this option is checked, the similar code fragments with different type names will be recognized as different. If this option is not checked, such code fragments will be recognized as duplicates.
If this option is checked, similar line of code with different litarels will be considered different If this option is not checked, such lines will be recognized as duplicates.
Ignore duplicates with complexity lower than
Complexity of the source code is defined by the amount of statements, expressions, declarations and method calls. Complexity of each of them is defined by its cost. Summarized costs of all these elements of the source code fragment yields the total complexity.
Ignore duplicate subexpressions with complexity lower than
Use this field to specify the lowest level of complexity of subexpressions to be taken into consideration when detecting duplicates.
Check if Subexpression Can be Extracted
If this option is checked, the duplicated subexpressions can be extracted.
Include / exclude patterns are newline-delimited set of rules of the form:
Where the pattern must satisfy these rules:
Some notes on patterns processing:
For the file paths to be reported correctly, "References to resources outside project/module file directory" option for the project and all modules should be set to "Relative" in IDEA project.