Set up maven-publish plugin for metalava library.

Now we have ./gradlew publish command that will publish metalava in
maven format to out/dist/

Test: ./gradlew publish -> creates a out/dist/repo directory with
metalava inside of it.
Bug: 138375208

Change-Id: I53515a7b73a3a388b038bad79e9a6ac7fd4a0d12
diff --git a/build.gradle.kts b/build.gradle.kts
index 489c5ac..3f91f60 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -27,6 +27,7 @@
     id("application")
     id("java")
     id("com.github.johnrengelman.shadow") version "4.0.4"
+    id("maven-publish")
 }
 
 group = "com.android"
@@ -157,3 +158,35 @@
     main = "com.pinterest.ktlint.Main"
     args = listOf("-F", "src/**/*.kt", "build.gradle.kts")
 }
+
+publishing {
+    publications {
+        create<MavenPublication>("metalavaLibrary") {
+            from(components["java"])
+            pom {
+                licenses {
+                    license {
+                        name.set("The Apache License, Version 2.0")
+                        url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
+                    }
+                }
+                developers {
+                    developer {
+                        name.set("The Android Open Source Project")
+                    }
+                }
+                scm {
+                    connection.set("scm:git:https://android.googlesource.com/platform/tools/metalava")
+                    url.set("https://android.googlesource.com/platform/tools/metalava/")
+                }
+            }
+        }
+    }
+
+    repositories {
+        maven {
+            name = "distRepo"
+            url = uri("file://${getDistributionDirectory().canonicalPath}/repo")
+        }
+    }
+}
\ No newline at end of file