## Specify a Java version

By default, buildpacks use the [latest supported version of Java](https://docs.cloud.google.com/docs/buildpacks/runtime-support#java) unless you specify a version. If your
application requires a specific version, you can use the
`GOOGLE_RUNTIME_VERSION` environment variable to specify a JDK version:

    pack build sample-java --builder=gcr.io/buildpacks/builder \
      --env GOOGLE_RUNTIME_VERSION=21


You can also use a `project.toml` project descriptor to encode
the environment variable alongside your project files. See instructions on
[building the application with environment variables](https://docs.cloud.google.com/docs/buildpacks/set-environment-variables#build_the_application_with_environment_variables)).

## Manage dependencies

Dependency configuration is supported for projects that use
Maven or Gradle.

### Configure Maven

Maven configurations can be applied using the `MAVEN_OPTS` environment variable.
See [documentation](https://maven.apache.org/configure.html) for
additional instructions.

Examples:

- `MAVEN_OPTS=-Xms256m -Xmx512m` passes these flags to the JVM running Maven.
- `MAVEN_OPTS=--add-opens java.base/java.lang=ALL-UNNAMED` to suppress "illegal reflective access" warnings from Maven.

To manage your project's dependency on Maven itself, you can use the
[Maven Wrapper](https://maven.apache.org/wrapper/). If you do not use the
Maven Wrapper, buildpacks defaults to using a recent version of Maven
when running `pack build`.

### Configure Gradle

Gradle configurations can be applied using the `GRADLE_OPTS` environment
variable. See
[documentation](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties)
for additional instructions.

Example:

`GRADLE_OPTS=-Xms256m -Xmx512m` passes these flags to the JVM running Gradle.

### Google Cloud hosted Maven Central mirror

You can use the hosted mirror of Maven Central by specifying the
[available URLs](https://storage-download.googleapis.com/maven-central/index.html).

#### Mirror repositories in Maven

To configure a mirror, follow the
[Using Mirrors for Repositories](https://maven.apache.org/guides/mini/guide-mirror-settings.html)
instructions in the Maven project documentation.

Create a copy of the `settings.xml` from the default location of
`~/.m2/settings.xml` to inside your application source directory and specify
`GOOGLE_BUILD_ARGS=--settings <path/to/settings>`.

**Note:** is relative to the source directory.

Example `settings.xml` file:

    <settings>
      <mirrors>
        <mirror>
          <id>google-maven-central</id>
          <name>Cloud Storage Maven Central mirror</name>
          <url>https://maven-central.storage-download.googleapis.com/maven2/</url>
          <mirrorOf>central</mirrorOf>
        </mirror>
      </mirrors>
    </settings>

#### Mirror repositories in Gradle

To configure a mirror, follow the
[Declaring Repositories](https://docs.gradle.org/current/userguide/declaring_repositories.html)
instructions in the Gradle project documentation.

Example `build.gradle` entry:

      repositories {
          maven {
              url "https://maven-central.storage-download.googleapis.com/maven2/"
          }
      }