pantsbuild / pants

The Pants Build System
https://www.pantsbuild.org
Apache License 2.0
3.32k stars 636 forks source link

When getting started with the JVM, it's not obvious how/when to create your intial lockfile #17521

Open stuhood opened 1 year ago

stuhood commented 1 year ago

To create a lockfile for the JVM, you need to run ./pants generate-lockfiles. But if you haven't done that, and have redefined the lockfile location, you will get a unmatched globs warning instead:

10:14:46.00 [ERROR] 1 Exception encountered:

  Exception: Unmatched glob from The resolve `jvm-default` from `[jvm].resolves`: "lib/3rdparty/jvm/default.lock"

Do the file(s) exist? If so, check if the file(s) are in your `.gitignore` or the global `pants_ignore` option, which may result in Pants not being able to see the file(s) even though they exist on disk. Refer to https://www.pantsbuild.org/v2.14/docs/troubleshooting#pants-cannot-find-a-file-in-your-project.

Rather than an unmatched glob, we should instead detect the missing file at a higher level, and explain how to create the lockfile. It looks like we already attempt to do that (in some cases): https://github.com/pantsbuild/pants/blob/c1514b73a6248a366228549c95bc1cc00fc2d93c/src/python/pants/jvm/resolve/coursier_fetch.py#L761-L767

... but apparently not in others.

rbuckland commented 1 year ago

The reproducible scenario is where the lock file exists, but it is empty.

❯ cat pants.toml 
[GLOBAL]
pants_version = "2.14.0"

backend_packages = [
  "pants.backend.python",
  "pants.backend.docker",
  "pants.backend.shell",
  'pants.backend.python.lint.black',
  'pants.backend.python.lint.isort',

  # antlr compiler
  "pants.backend.experimental.java",
]

[python]
# This will become the default in Pants 2.15.
tailor_pex_binary_targets = false

[jvm]
jdk = "temurin:1.17"

[jvm.resolves]
jvm-default = "lib/3rdparty/jvm/default.lock"

❯ echo > lib/3rdparty/jvm/default.lock 

❯ ./pants run  path/to-something/with/jar/dependency 
10:26:46.04 [ERROR] 1 Exception encountered:

  KeyError: 'entries'
rbuckland commented 1 year ago

the other scenario is where the lockfile does not exist, as per the original issue description. my "activities" were

stuhood commented 1 year ago
  • run pants and it errored that the file did not exist (see issue description)

Which command did you run, in particular?

rbuckland commented 1 year ago

@stuhood - these steps - https://github.com/pantsbuild/pants/issues/17521#issuecomment-1309536599