Lee Avital
Lee Avital

Reputation: 542

How do I add a command line argument to a jvm_binary target?

I have a JVM binary target that looks like:

jvm_binary(
  name = "server-binary",
  dependencies = [
    ":server-library",
    "static_files:make"
  ],
  main= "Main",
)

I can add command line arguments to the server like so:

./pants run server:server-binary --jvm-run-jvm-program-args='-port:9000'

But I'd like to have to have some arguments be part of the target, so I don't have to specify the arguments on the command line everytime I invoke pants.

Ideally I could type something like:

jvm_binary(
  name = "server-binary",
  dependencies = [
    ":server-library",
    "static_files:make"
  ],
  main= "Main",
  args = {
     "--jvm-run-jvm-program-args": "-port:9000"
  }
)

Is there a way to do this?

Upvotes: 2

Views: 273

Answers (1)

ericzundel
ericzundel

Reputation: 550

You can use a jvm_prep_command() that depends on your jvm_library() targets:

Here's an example from our repo:

jvm_prep_command(name='migrate',
  goal='run',
  mainclass='com.squareup.dbmigrate.tools.Migrator',
  args=[
    '--url="jdbc:mysql://localhost/sms_development"',
    '--type="sql:mysql"',
    '--username="root"',
    '--password=""',
    '--migrations-dir="sms/src/main/resources/sql/sms/migrations"',
  ],
  dependencies=[
    'dbmigrate:lib'
  ],
)

Run this with ./pants run sms:migrate

Upvotes: 2

Related Questions