Skip to content

Commit

Permalink
Add tool classpath for ./pants scalafix (#6926)
Browse files Browse the repository at this point in the history
### Problem

Same as in pr #6922
In order to run custom scalafix rules that are distributed in .jar form, they must be added to scalafix's '--tool-classpath' command line argument. Currently there is no way to set this argument from pants.

### Solution

Add scalafix-tool-classpath via register_jvm_tool to ./pants scalafix, with default empty classpath so you don't need to add a target if you don't want.

### Result

scalafix_tool_classpath can be set in pants.ini or on the command line, and scalafix will be able to load your precompiled custom rules.
  • Loading branch information
woparry authored and illicitonion committed Dec 17, 2018
1 parent 6f0694e commit 04a835e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/python/pants/backend/jvm/tasks/scalafix.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def register_options(cls, register):
classpath=[
JarDependency(org='ch.epfl.scala', name='scalafix-cli_2.11.11', rev='0.5.2'),
])
cls.register_jvm_tool(register, 'scalafix-tool-classpath', classpath=[])

@classmethod
def target_types(cls):
Expand All @@ -58,6 +59,9 @@ def _compute_classpath(self, targets):

def invoke_tool(self, absolute_root, target_sources):
args = []
tool_classpath = self.tool_classpath('scalafix-tool-classpath')
if tool_classpath:
args.append('--tool-classpath={}'.format(':'.join(tool_classpath)))
if self.get_options().semantic:
# If semantic checks are enabled, pass the relevant classpath entries for these
# targets.
Expand Down

0 comments on commit 04a835e

Please sign in to comment.