IntelliJ Plug-in for Pants Build
Java Python Shell Scala HTML
Clone or download
wisechengyi Adopt unique module path to avoid module creation lockup (#359)
### Problem

The stacktrace shows my earlier suspicion before on module create lock between projects: if target X is in both project A and B, then both projects will create module X whose module definition file isn't unique at this point, causing a dead lock.

	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl$$Lambda$1909/ Source)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl.applyProjectSdk(
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl.access$1300(
	at com.twitter.intellij.pants.components.impl.PantsProjectComponentImpl$1$1.moduleAdded(
	at sun.reflect.GeneratedMethodAccessor69.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(
	at java.lang.reflect.Method.invoke(
	at com.intellij.util.messages.impl.MessageBusConnectionImpl.deliverMessage(
	at com.intellij.util.messages.impl.MessageBusImpl.doPumpMessages(
	at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(
	at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(
	at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(
	at com.intellij.util.messages.impl.MessageBusImpl.sendMessage(
	at com.intellij.util.messages.impl.MessageBusImpl.access$200(
	at com.intellij.util.messages.impl.MessageBusImpl$2.invoke(
	at com.sun.proxy.$Proxy135.moduleAdded(Unknown Source)
	at com.intellij.openapi.module.impl.ModuleManagerImpl.fireModuleAdded(
	at com.intellij.openapi.module.impl.ModuleManagerImpl.lambda$commitModel$5(
	at com.intellij.openapi.module.impl.ModuleManagerImpl$$Lambda$1905/ Source)
	at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.makeRootsChange(
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModel(
	at com.intellij.openapi.module.impl.ModuleManagerImpl.access$1500(
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.commitWithRunnable(
	at com.intellij.openapi.module.impl.ModuleManagerImpl$ModuleModelImpl.access$1200(
	at com.intellij.openapi.module.impl.ModuleManagerImpl.commitModelWithRunnable(
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(
	at com.intellij.openapi.roots.impl.ModifiableModelCommitter.multiCommit(

### Solution

Assign a unique parent directory for modules at each import. The implementation uses a hash from the timestamp.

### Result

Verified multiple imports of the same target do not cause a lockup.
Latest commit 448182b Jun 30, 2018
Failed to load latest commit information.
.idea Upgrade to 2018.1 compatibility (#335) Mar 13, 2018
3rdparty/intellij Upgrade to 2018.1 compatibility (#335) Mar 13, 2018
common Restrict BUILD file change popup to Pants project (#358) Jun 28, 2018
images Remove IntelliJ compiler option, isolate strategy checking, and expor… Feb 11, 2016
jps-plugin Add usage extension points (#238) Jan 4, 2017
resources Prepare 1.9.2 release (#356) Jun 28, 2018
scripts Bump IJ to 2018.1.5 and plugins (#357) Jun 25, 2018
src Adopt unique module path to avoid module creation lockup (#359) Jun 30, 2018
testData Exclude jars imported into the project for IntelliJ Junit/Scala runner ( Feb 28, 2018
testFramework Make scala plugin an optional dependency (#352) Jun 6, 2018
tests Make scala plugin an optional dependency (#352) Jun 6, 2018
.gitignore Add test to import whole repo; include buildroot name into project na… Sep 13, 2016
.travis.yml Bump IJ to 2018.1.5 and plugins (#357) Jun 25, 2018 Update to 2017.3 (#319) Dec 6, 2017 Set up more of the module classpath in the project (#345) Apr 25, 2018 updating contributors file Jun 30, 2016
LICENSE add LICENSE, to root, add license to java,scala,prope… Oct 31, 2014 Readme/Contributing guideline update (#222) Dec 2, 2016
intellij-pants-plugin.iml Tweak module dependency scope (#346) Apr 26, 2018
pants Upgrade test target to be 2017.1.2 (#292) May 8, 2017
pants-beta-updates.xml Disabled beta build Oct 8, 2015
pants.ini Update to 2017.3 (#319) Dec 6, 2017


  • The intellij-pants-plugin supports importing, compiling and testing Pants projects.
  • Scala and Java projects are fully supported. Python projects are supported on a best effort basis.
  • As of 12/2/2016, latest version of the plugin supports IntelliJ IDEA 2016.3 and up for both Community Edition and Ultimate Edition.
  • As of 12/2/2016, the plugin supports 1.1.x, 1.2.x, and current master of Pants.

User documentation

Installing the Plugin

Please use Plugins tab: (Main menu: Settings | Plugins) to install the plugin. Find Pants Support plugin. Install and Restart IntelliJ.

Minimum set of plugins is required to enable Pants Support features

  • Gradle
  • Groovy
  • Java Bytecode Decompiler
  • JUnit
  • Python Community Edition (if you are importing python projects)
  • Scala

Importing an entire project directory

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select project directory Import project from directory
  • Choose "Pants" on the next screen
  • Make sure the check box "All Targets in the directory" is enabled and proceed with the wizard

Importing targets from a BUILD File

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select a Build File from within the project Import project from BUILD file
  • Check the targets you want to Import and proceed with the wizard. (Please wait for the targets to show up) Choose Targets

Importing targets from a script

  • Use Main menu: File -> New -> Project From Existing Sources
  • Select an executable that will use export goal to produce a desirable project structure. See an integration test as an example.

Importing multiple BUILD files/directories

  • Import the first directory/BUILD file
  • Use File -> New -> Module From Existing Sources to import next directories/BUILD files

Once you import the project using above steps, you will see the "Project View" with multiple modules configured.

Invoking Pants within IntelliJ

The plugin can invoke any Pants commands via Pants Tasks.

  • To configure a Pants Task simply create a new Pants Run Configuration Creating of a new Pants Run Configuration
  • Choose a target to run a task for Choosing a target Configured target
  • Fill the rest of options for the task. Note there is a task for each Pants goal. Configure Pants Task
  • Run the Task Configured Pants Task
  • To debug a task simply press Debug button next to Run button.
  • Note: you can create a task for any goal Bundle Task

Predefined Pants Tasks for test targets

The plugin can also generate test configurations.

For example if a test class is opened then with a right click it's easy to create a task to run and debug Run Configuration Producer Preconfigured Run Configuration

With a right click in Project View it's easy to create a test task to run all tests for a target Run Configuration Producer


  • Pants' compile goal (Default) The plugin will use pants compile <list of targets> to compile your project once a Make or PantsCompile command is invoked. Compilation via compile goal

Compilation options can be configured in Preferences -> Build, Execution, Deployment -> Compiler -> Pants: Compilation Options

Plugin Features.

  • Project File Tree View. The plugin configures modules per pants build target. Due to multiple modules, the default "Project View" is not very user friendly. The Plugin provides a custom view "Project Files Tree View". This view adheres to your repository file hierarchy. You can switch to this view as follows: Project Files Tree View "Project Files Tree View" also provides an ability to filter out files that weren't loaded during project generation. Show Only Loaded Files
  • Project Regeneration using IntelliJ Action. If you add a dependency to your project, you can re-resolve project using IntelliJ Action in background. Use Main Menu: Help -> Find Action or Short hand Cmd+Shift+A and select Action "Refresh all External Projects" Remember to check "Include non-menu actions" Refresh Project
  • Running tests within IntelliJ You can right click on tests and run tests.

Report Bugs

If you encounter a bug, please check for existing issues or file a new one on the project page.