1 /* 2 * Copyright (C) 2025 The Dagger Authors. 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 dagger.gradle.build 18 19 import com.vanniktech.maven.publish.MavenPublishBaseExtension 20 import com.vanniktech.maven.publish.SonatypeHost 21 import org.gradle.api.Plugin 22 import org.gradle.api.Project 23 24 class PublishConventionPlugin : Plugin<Project> { applynull25 override fun apply(project: Project) { 26 project.pluginManager.apply(project.getPluginIdByName("publish")) 27 28 project.plugins.withId(project.getPluginIdByName("publish")) { 29 val publishExtension = project.extensions.getByName("mavenPublishing") as MavenPublishBaseExtension 30 publishExtension.apply { 31 coordinates( 32 groupId = "com.google.dagger", 33 artifactId = project.name, 34 version = project.findProperty("PUBLISH_VERSION").toString() 35 ) 36 publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) 37 pom { 38 name.set(project.name.asPomName()) 39 description.set("A fast dependency injector for Android and Java.") 40 url.set("https://github.com/google/dagger") 41 scm { 42 url.set("https://github.com/google/dagger/") 43 connection.set("scm:git:git://github.com/google/dagger.git") 44 } 45 issueManagement { 46 system.set("GitHub Issues") 47 url.set("https://github.com/google/dagger/issues") 48 } 49 licenses { 50 license { 51 name.set("The Apache Software License, Version 2.0") 52 url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") 53 } 54 } 55 organization { 56 name.set("Google, Inc.") 57 url.set("https://www.google.com") 58 } 59 } 60 } 61 } 62 } 63 64 /** 65 * Converts the Gradle project name to a more appropriate name for the POM file. 66 * 67 * For example: 'dagger-compiler' to 'Dagger Compiler' 68 */ asPomNamenull69 private fun String.asPomName(): String { 70 val parts = split("-").map { first().uppercaseChar() + drop(1) } 71 return parts.joinToString(separator = " ") 72 } 73 }