1 /*
2 * Copyright (C) 2020 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.tools.metalava
18
19 import java.io.File
20 import org.gradle.api.Project
21 import org.gradle.api.file.Directory
22 import org.gradle.api.provider.Provider
23 import org.gradle.api.tasks.TaskProvider
24 import org.gradle.api.tasks.bundling.Zip
25
26 const val CREATE_ARCHIVE_TASK = "createArchive"
27
configurePublishingArchivenull28 fun configurePublishingArchive(
29 project: Project,
30 publicationName: String,
31 repositoryName: String,
32 buildId: String,
33 distributionDirectory: File,
34 projectRepo: Provider<Directory>
35 ): TaskProvider<Zip> {
36 return project.tasks.register(CREATE_ARCHIVE_TASK, Zip::class.java) {
37 it.description = "Create a zip of the library in a maven format"
38 it.group = "publishing"
39
40 it.from(projectRepo)
41 it.archiveFileName.set(
42 project.provider {
43 "per-project-zips/${project.group}-${project.name}-all-$buildId-${
44 project.version().get()
45 }.zip"
46 }
47 )
48 it.destinationDirectory.set(distributionDirectory)
49 it.dependsOn("publish${publicationName}PublicationTo${repositoryName}Repository")
50 }
51 }
52