// Metadata created by nebel
// ParentAssemblies: assemblies/getting-started/as_installing-the-registry.adoc

[id="downloading-artifacts-using-maven-plugin_{context}"]
= Downloading schema and API artifacts using the Maven plug-in

[role="_abstract"]
You can use the Maven plug-in to download artifacts from {registry}. This is often useful, for example, when generating code from a registered schema.

.Prerequisites
* You have created a Maven project for your client application. For more details, see the https://maven.apache.org/index.html[Apache Maven documentation].

.Procedure
. Update your Maven `pom.xml` file to use the `apicurio-registry-maven-plugin` to download an artifact. The following example shows downloading Apache Avro and GraphQL schemas.
+
[source,xml]
----
<plugin>
  <groupId>io.apicurio</groupId>
  <artifactId>apicurio-registry-maven-plugin</artifactId>
  <version>${apicurio.version}</version>
  <executions>
    <execution>
      <phase>generate-sources</phase>
      <goals>
        <goal>download</goal> <1>
      </goals>
      <configuration>
          <registryUrl>MY-REGISTRY-URL/apis/registry/v2</registryUrl> <2>
          <authServerUrl>MY-AUTH-SERVER</authServerUrl> 
          <clientId>MY-CLIENT-ID</clientId>
          <clientSecret>MY-CLIENT-SECRET</clientSecret> <3>
          <clientScope>MY-CLIENT-SCOPE</clientScope>
          <artifacts>
              <artifact>
                  <groupId>TestGroup</groupId> <4>
                  <artifactId>FullNameRecord</artifactId> <5>
                  <file>${project.build.directory}/classes/record.avsc</file>
                  <overwrite>true</overwrite>
              </artifact>
              <artifact>
                  <groupId>TestGroup</groupId>
                  <artifactId>ExampleAPI</artifactId>
                  <version>1</version>
                  <file>${project.build.directory}/classes/example.graphql</file>
                  <overwrite>true</overwrite>
              </artifact>
          </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>
----
+
<1> Specify `download` as the execution goal.
<2> Specify the {registry} URL with the `../apis/registry/v2` endpoint.
ifdef::apicurio-registry,rh-service-registry[]
<3> If authentication is required, you can specify your authentication server and client credentials.
endif::[]
ifdef::rh-openshift-sr[]
<3> Specify your service account ID and secret and {org-name} Single Sign-On authentication server: `{sso-token-url}`
endif::[]
<4> Specify the {registry} artifact group ID. You can specify the `default` group if you do not want to use a unique group.
<5> You can download multiple artifacts to a specified directory using the artifact ID.

. Build your Maven project, for example, by using the `mvn package` command. 

[role="_additional-resources"]
.Additional resources
 * For more details on using Apache Maven, see the https://maven.apache.org/index.html[Apache Maven documentation].
 * For open source examples of using the {registry} Maven plug-in, see the link:https://github.com/Apicurio/apicurio-registry-examples[Apicurio Registry demonstration examples].
