# Maven dependencies

Elide resolves Maven dependencies declared in `elide.pkl` or a `pom.xml`.

```bash
elide install
```

Maven is the default ecosystem. Buckets, repositories, credentials and install options:
[Dependencies](/docs/toolchain/dependencies).

## Kotlin Multiplatform libraries

Kotlin Multiplatform libraries such as `com.squareup.okhttp3:okhttp` 5, `io.ktor:ktor-client-core` and
`org.jetbrains.kotlinx:kotlinx-coroutines-core` publish their JVM classes in a separate module, such as
`okhttp-jvm`. Declare the library itself:

```pkl
dependencies {
  maven {
    packages { "com.squareup.okhttp3:okhttp:5.1.0" }
  }
}
```

When a library's POM announces Gradle Module Metadata, `elide install` installs the JVM module the metadata names,
with its dependencies, and the declared coordinate resolves to it on every classpath. The metadata comes from the
repository that served the POM. Libraries that publish their classes under their own coordinate, and POMs that
announce no metadata, are unchanged and cost no extra request.

Metadata that cannot be read, or that names more than one JVM module, fails the install, and so does metadata a
POM announces that an offline install has not downloaded before.

To read every library from its POM alone, set `gradleMetadata = false`:

```pkl
dependencies {
  maven {
    gradleMetadata = false
  }
}
```

In a workspace, the root's `gradleMetadata = false` applies to every member. Without it,
`elide build deps --no-gradle-module-metadata` turns redirects off for one build, and `ELIDE_GRADLE_MODULE_METADATA=0`
does so for `elide install`; an explicit `--gradle-module-metadata` outranks the variable. Neither turns redirects on
when the manifest turns them off. Changing any of these resolves the graph again.

A graph resolved by an earlier Elide keeps the library's own coordinate until the dependency list changes. Run
`elide install --fresh` once to install the JVM modules.

## Projects with only a `pom.xml`

```bash
elide install -p .
```

Elide reads the POM's direct dependencies, `${property}` values and its own `dependencyManagement`. Parents and
imported BOMs are not merged; a dependency versioned only by a parent is dropped.

| POM scope | Bucket |
| --- | --- |
| `compile` | `packages` |
| `provided`, `system` | `compileOnly` |
| `runtime` | `runtimeOnly` |
| `test` | `testPackages` |

To build it with Maven and Elide's compilers, use the [Maven plugin](/docs/build-tools-maven).

## Inspect dependency code

In an `elide.pkl` project, the experimental [dependency code index](/docs/toolchain/jvm/code-index) records types,
members, and references from resolved Maven JARs. Use `elide index resolve` to find a class's defining artifact,
or `elide index references` to inspect what a dependency class uses.

[OpenRewrite](/docs/toolchain/jvm/rewrite) uses that index to run Java recipes. Declare additional recipe modules under
`dependencies.maven.devPackages` and preview source changes with `--dry-run`.

## Annotation processors

```pkl
dependencies {
  maven {
    packages { "org.mapstruct:mapstruct:1.6.3" }
    processors { "org.mapstruct:mapstruct-processor:1.6.3" }
  }
}
```

- Processors run in `elide build` and `elide javac`, on main and test source sets.
- A changed processor JAR recompiles.
- Generated sources go to `.dev/jvm/generated-sources/<set>/java` and compile with the set.
- Processors see Java sources only, never Kotlin declarations. Kotlin compiles before Java processing, so Kotlin code
  that uses generated types must get them from an upstream source set or project.
- Project builds don't run processors over Kotlin (KAPT), except Android projects with `processors` declared; KSP is unsupported.
- `-proc:none`, `-proc:only` and `-proc:full` behave as in `javac`.

`elide javac --capabilities` reports what this Elide build supports:

```json
{
  "version": 1,
  "javaAnnotationProcessing": true,
  "javacPlugins": true,
  "kotlinSymbolProcessing": false,
  "kotlinCompilerPlugins": false
}
```

| Field | Meaning |
| --- | --- |
| `javaAnnotationProcessing` | Java annotation processors run. |
| `javacPlugins` | `javac` `-Xplugin` plugins such as Error Prone and NullAway run. |
| `kotlinSymbolProcessing` | KSP processors run. |
| `kotlinCompilerPlugins` | Third-party Kotlin compiler plugins run in the embedded compiler. Built-in plugins and a [managed or custom toolchain](/docs/toolchain/jvm/kotlinc#choose-a-toolchain) are not affected. |

Set `ELIDE_TRACE_PROCESSORS=1` to print each processor class as it loads (`Loading processor dependency:
demo.HelloProcessor`).
