# Maven Repository<no value>
// <!-- Required for asciidoctor -->
:toc:
// Set toclevels to be at least your hugo [markup.tableOfContents.endLevel] config key
:toclevels: 4

[cols="1^,1^,1^",options=header]
|===
| source | condition | target
| &#10004; | &#10004; | &#10007;
|===

== Description

The `maven` resource reads the `maven-metadata.xml` of an artifact and returns a version from it.

**source**::
Returns the version matching `versionfilter`.

**condition**::
Checks that `version` exists for the artifact.

**target**::
Not supported - a target fails with `Target not supported for the plugin Maven`. To write a version *into* a `pom.xml`, use the link:/docs/plugins/resource/xml/["XML" resource], or the link:/docs/plugins/autodiscovery/maven/[maven autodiscovery crawler].

NOTE: An `scm` attached to a condition is not supported and aborts it with `SCM configuration is not supported for maven condition, aborting`.

== Parameters

{{< resourceparameters "sources" "maven" >}}

`groupid` and `artifactid` identify the artifact; the group's dots become path separators when the metadata URL is built. `version` is condition-only.

`repository` and `repositories` are mutually exclusive (setting both is rejected with `parameter "repository" and "repositories" are mutually exclusive`).

NOTE: `url` is deprecated. It is prepended to `repository` and logs `Parameter "URL" is deprecate, please prefix its content to parameter "repository"`. Put the whole URL in `repository` instead.

== Repositories

[IMPORTANT]
====
**Maven Central is always consulted.** Unless `https://repo.maven.apache.org/maven2` already appears in `repositories`, Updatecli appends it as the last repository to try.

A lookup against a private repository therefore falls through to Maven Central rather than failing when the artifact is missing (which is convenient for public dependencies, and surprising if you expected an internal-only artifact to be resolved internally or not at all).
====

`repositories` is ordered: the first repository that answers wins, with Maven Central last. Use it when an artifact may live in either a snapshot or a release repository:

[source,yaml]
----
spec:
  repositories:
    - https://repo.jenkins-ci.org/releases
    - https://repo.jenkins-ci.org/public
  groupid: org.jenkins-ci.main
  artifactid: jenkins-war
----

NOTE: `repository` can carry Basic Auth credentials in the standard notation, `username:password@hostname`. Use link:/docs/core/templating/[templating] to keep the password out of the manifest.

== Example

[source,yaml]
----
# updatecli.yaml
{{<include "assets/code_example/docs/plugins/resources/maven/updatecli.d/default.yaml">}}
----

What it says:

**Sources**::
Retrieve the version of the artifact `jenkins-war` from the group `org.jenkins-ci.main` in the `releases` repository on `repo.jenkins-ci.org` (2.264), then append `jdk11`, giving `2.264-jdk11`.

**Conditions**::
Check that a Docker image `jenkins/jenkins:2.264-jdk11` is published on DockerHub, and that the key `jenkins.master.image` in `charts/jenkins/values.yaml` is set to `jenkins/jenkins`. Either failing stops the pipeline.

**Targets**::
Update `jenkins.master.imageTag` to `2.264-jdk11` in that file and commit the change.

== Links

* link:https://maven.apache.org/repositories/metadata.html[Maven repository metadata]
* link:/docs/core/versionfilter/["Version Filtering" page]
