diff --git a/docs/docs/jvm/java-and-scala.mdx b/docs/docs/jvm/java-and-scala.mdx index 3a69544881a..0c1da76a334 100644 --- a/docs/docs/jvm/java-and-scala.mdx +++ b/docs/docs/jvm/java-and-scala.mdx @@ -117,6 +117,91 @@ To efficiently determine which symbols are provided by thirdparty code (i.e., wi The `packages` argument allows you to override which symbols a `jvm_artifact` provides. See the [`jvm_artifact` docs](../../reference/targets/jvm_artifact.mdx#packages) for more information. ::: +To enable better IDE integration, Pants has `jvm_artifacts` target generator to +generate `jvm_artifact` targets for you. + +### `pom.xml` + +The `jvm_artifacts()` target generator parses a +[`pom.xml`](https://maven.apache.org/guides/introduction/introduction-to-the-pom.html) +to produce a `jvm_artifact` target for each `dependency` in +`project.dependencies`. + +For example: + +```xml tab={"label":"pom.xml"} + + + + com.google.guava + guava + 33.2.0-jre + + + org.apache.commons + commons-lang3 + 3.14.0 + + + +``` + +```python tab={"label":"BUILD"} +# This will generate two targets: +# +# - //:reqs#guava +# - //:reqs#commons-lang3 +jvm_artifacts(name="reqs") +``` + +The above target generator is spiritually equivalent to this: + +```python title="BUILD" +jvm_artifact( + group="com.google.guava", + artifact="guava", + version="33.2.0-jre", +) +jvm_artifact( + group="org.apache.commons", + artifact="commons-lang3", + version="3.14.0", +) +``` + +To define `jvm_artifact` packages use `package_mapping` field: + +```python tab={"label":"BUILD"} +jvm_artifacts( + name="reqs", + package_mapping={ + "com.google.guava:guava": [ + "com.google.common.**", + ], + "org.apache.commons:commons-lang3": [ + "org.apache.commons.lang3.**", + ], + }, +) +``` + +```xml tab={"label":"pom.xml"} + + + + com.google.guava + guava + 33.2.0-jre + + + org.apache.commons + commons-lang3 + 3.14.0 + + + +``` + ### `resource` targets To have your code [load files as "resources"](https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html): diff --git a/docs/notes/2.22.x.md b/docs/notes/2.22.x.md index adf5f442b68..56717897472 100644 --- a/docs/notes/2.22.x.md +++ b/docs/notes/2.22.x.md @@ -32,6 +32,10 @@ docs [here](https://www.pantsbuild.org/2.22/docs/sql). #### JVM +[Added documentation](https://www.pantsbuild.org/2.22/docs/jvm/java-and-scala#pomxml) +for [`jvm_artifacts`](https://www.pantsbuild.org/2.22/reference/targets/jvm_artifacts) +targets generator from `pom.xml`. + ##### Scala Setting the `orphan_files_behaviour = "ignore"` option for [`pants.backend.experimental.scala.lint.scalafix`](https://www.pantsbuild.org/2.22/reference/subsystems/scalafix#orphan_files_behavior) or [`pants.backend.experimental.scala.lint.scalafmt`](https://www.pantsbuild.org/2.22/reference/subsystems/scalafmt#orphan_files_behavior) backend is now properly silent. It previously showed spurious warnings.