# POM export and native Maven

> Hand an Elide project to Maven and other tools with `elide project export` (POM, JSON, IntelliJ model), and build the result with `elide mvn` or stock Maven.

`elide project export` renders an `elide.pkl` project as a model other tools read. `--format=pom` writes a Maven
`pom.xml`, which `elide mvn` or any Maven 3.9+ install builds.

## Export

```bash
elide project export --format=pom > pom.xml
elide project export --format=json          # resolved manifest
elide project export --format=intellij      # IntelliJ workspace model
elide project export -p app --format=pom    # another project directory
```

Pass the format as `--format=<value>`; the output goes to stdout.

| Format | Contents |
| --- | --- |
| `json` (default) | The manifest after Pkl evaluation |
| `pom` | A Maven POM: coordinates, dependencies with scopes, compiler release, source roots |
| `intellij` | Modules per source set, content and source roots, library dependencies, JDK level |

### What the POM contains

| `elide.pkl` | `pom.xml` |
| --- | --- |
| `name` | `<groupId>`, `<artifactId>` and `<name>` (a workspace member takes the workspace name as `<groupId>`) |
| `version` | `<version>`; `0.0.0` when unset |
| `jvm.target`, `jvm.java.release` | `maven.compiler.release`, `.source`, `.target` |
| `packages`, `modules` | compile scope |
| `compileOnly`, `devPackages`, `processors` | `provided` |
| `runtimeOnly` | `runtime` |
| `testPackages` | `test` |
| A local JAR path | `system` scope with `${project.basedir}` path |
| Source sets | `<sourceDirectory>`, `<testSourceDirectory>`; extra roots through `build-helper-maven-plugin` |
| Workspace members | `<modules>` on the root, `<parent>` on each member |
| A `Jar.from` sibling | Its `packages`, `modules` and `runtimeOnly`, unless already listed |

Not exported: `exclusions`, `substitutions` and `kotlinPlugins`. Repositories declared in the manifest are exported.

## Build the POM

| Runner | Command | Needs |
| --- | --- | --- |
| [Native Maven](https://elide.help/docs/toolchain/jvm/native-maven) | `elide mvn -- package` | Nothing else |
| Stock Maven 3.9+ | `mvn package` | `JAVA_HOME` set to the Elide distribution, or any JDK |

Point `JAVA_HOME` at the directory that holds `bin/elide`; its `bin/java` and `bin/javac` run Maven, its compiler and
its forked test JVMs as a JDK 25 would:

```bash
export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v elide)")")")"
mvn package
```

To compile with `elide javac` and `elide kotlinc` inside an existing POM, use the [Maven plugin](https://elide.help/docs/build-tools-maven).

## Example

```pkl
amends "elide:project.pkl"

name = "hello"
version = "1.0.0"

dependencies {
  maven {
    packages { "com.google.guava:guava:33.4.8-jre" }
    testPackages { "org.junit.jupiter:junit-jupiter:5.13.4" }
  }
}

jvm {
  main = "com.example.Hello"
  target = 17
}
```

```bash
elide project export --format=pom > pom.xml
```

```xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>hello</groupId>
  <artifactId>hello</artifactId>
  <version>1.0.0</version>
  <name>hello</name>
  <properties>
    <maven.compiler.release>17</maven.compiler.release>
    <maven.compiler.target>17</maven.compiler.target>
    <maven.compiler.source>17</maven.compiler.source>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.google.guava</groupId>
      <artifactId>guava</artifactId>
      <version>33.4.8-jre</version>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter</artifactId>
      <version>5.13.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src/main/java</sourceDirectory>
    <testSourceDirectory>src/test/java</testSourceDirectory>
  </build>
</project>
```

```bash
elide mvn -- package
```

```terminaloutput
Running com.example.HelloTest
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.275 s -- in com.example.HelloTest
Building jar: target/hello-1.0.0.jar
BUILD SUCCESS
Total time:  5.041 s
```

## Limits

- The export is one-way: Elide never reads the generated file back. Regenerate it after changing `elide.pkl`.
- `name` becomes the coordinates. A name with spaces or other characters Maven rejects needs a hand-edited
  `<groupId>` and `<artifactId>`.
- Only `build-helper-maven-plugin` is declared. Kotlin sources need a Kotlin compiler added to the build, such as
  [Elide's](https://elide.help/docs/build-tools-maven).
- Elide's built-in test dependencies are not added; declare test frameworks in `testPackages`.
