Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for jvm_artifacts target generator #20890

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
85 changes: 85 additions & 0 deletions docs/docs/jvm/java-and-scala.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
<project>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.0-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
```

```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"}
<project>
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>33.2.0-jre</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.14.0</version>
</dependency>
</dependencies>
</project>
```

### `resource` targets

To have your code [load files as "resources"](https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html):
Expand Down
4 changes: 4 additions & 0 deletions docs/notes/2.22.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down