-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
build logic + better publishing #760
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
plugins { | ||
alias(libs.plugins.kotlin.jvm) | ||
alias(libs.plugins.ktlint) | ||
id 'java-gradle-plugin' | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
module { | ||
id = "library" | ||
implementationClass = "com.squareup.anvil.LibraryPlugin" | ||
} | ||
root { | ||
id = "root" | ||
implementationClass = "com.squareup.anvil.RootPlugin" | ||
} | ||
publish { | ||
id = "publish" | ||
implementationClass = "com.squareup.anvil.PublishConventionPlugin" | ||
} | ||
} | ||
} | ||
|
||
kotlin { | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
dependencies { | ||
compileOnly(gradleApi()) | ||
implementation libs.ktlintRaw | ||
implementation libs.kgx | ||
implementation libs.kotlinpoet | ||
implementation libs.kotlin.dokka | ||
implementation libs.kotlin.gradlePlugin | ||
implementation libs.mavenPublishRaw | ||
} | ||
|
||
ktlint { | ||
version = libs.versions.ktlint.get() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
build-logic/src/main/kotlin/com/squareup/anvil/KtlintConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.squareup.anvil | ||
|
||
import com.rickbusarow.kgx.libsCatalog | ||
import com.rickbusarow.kgx.version | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.jlleitschuh.gradle.ktlint.KtlintExtension | ||
import org.jlleitschuh.gradle.ktlint.KtlintPlugin | ||
|
||
open class KtlintConventionPlugin : Plugin<Project> { | ||
|
||
override fun apply(target: Project) { | ||
target.plugins.apply(KtlintPlugin::class.java) | ||
|
||
target.plugins.apply(org.jlleitschuh.gradle.ktlint.KtlintPlugin::class.java) | ||
|
||
target.extensions.configure(KtlintExtension::class.java) { ktlint -> | ||
ktlint.version.set(target.libsCatalog.version("ktlint")) | ||
ktlint.verbose.set(true) | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
build-logic/src/main/kotlin/com/squareup/anvil/PublishConventionPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.squareup.anvil | ||
|
||
import com.vanniktech.maven.publish.JavadocJar | ||
import com.vanniktech.maven.publish.KotlinJvm | ||
import com.vanniktech.maven.publish.MavenPublishBaseExtension | ||
import com.vanniktech.maven.publish.Platform | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.publish.tasks.GenerateModuleMetadata | ||
import org.gradle.api.tasks.bundling.Jar | ||
import javax.inject.Inject | ||
|
||
open class PublishConventionPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
|
||
target.plugins.apply("com.vanniktech.maven.publish.base") | ||
target.plugins.apply("org.jetbrains.dokka") | ||
|
||
target.extensions.create("publish", PublishExtension::class.java) | ||
|
||
val mavenPublishing = target.extensions | ||
.getByType(MavenPublishBaseExtension::class.java) | ||
|
||
val pluginPublishId = "com.gradle.plugin-publish" | ||
|
||
@Suppress("UnstableApiUsage") | ||
mavenPublishing.pomFromGradleProperties() | ||
mavenPublishing.signAllPublications() | ||
|
||
target.plugins.withId("org.jetbrains.kotlin.jvm") { | ||
|
||
when { | ||
target.plugins.hasPlugin(pluginPublishId) -> { | ||
// Gradle's 'plugin-publish' plugin creates its own publication. We only apply this plugin | ||
// in order to get all the automated POM configuration. | ||
} | ||
|
||
else -> { | ||
configurePublication( | ||
target, | ||
mavenPublishing, | ||
KotlinJvm(javadocJar = JavadocJar.Dokka("dokkaHtml"), sourcesJar = true) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Suppress("UnstableApiUsage") | ||
private fun configurePublication( | ||
target: Project, | ||
mavenPublishing: MavenPublishBaseExtension, | ||
platform: Platform | ||
) { | ||
mavenPublishing.configure(platform) | ||
|
||
target.tasks.withType(GenerateModuleMetadata::class.java).configureEach { | ||
it.mustRunAfter(target.tasks.withType(Jar::class.java)) | ||
it.mustRunAfter("dokkaJavadocJar") | ||
it.mustRunAfter("kotlinSourcesJar") | ||
} | ||
} | ||
} | ||
|
||
open class PublishExtension @Inject constructor( | ||
private val target: Project, | ||
) { | ||
fun configurePom(args: Map<String, Any>) { | ||
|
||
val artifactId = args.getValue("artifactId") as String | ||
val pomName = args.getValue("pomName") as String | ||
val pomDescription = args.getValue("pomDescription") as String | ||
|
||
target.extensions | ||
.getByType(PublishingExtension::class.java) | ||
.publications.withType(MavenPublication::class.java) | ||
.matching { !it.name.endsWith("PluginMarkerMaven") } | ||
.configureEach { publication -> | ||
|
||
// Gradle plugin publications have their own artifactID convention, | ||
// and that's handled automatically. | ||
if (!publication.name.endsWith("PluginMarkerMaven")) { | ||
publication.artifactId = artifactId | ||
} | ||
|
||
publication.pom { | ||
it.name.set(pomName) | ||
it.description.set(pomDescription) | ||
} | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
build-logic/src/main/kotlin/com/squareup/anvil/RootPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.squareup.anvil | ||
|
||
import com.squareup.anvil.benchmark.BenchmarkPlugin | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformJvmPlugin | ||
|
||
open class RootPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
target.plugins.apply(BenchmarkPlugin::class.java) | ||
target.plugins.apply(KtlintConventionPlugin::class.java) | ||
} | ||
} | ||
|
||
open class LibraryPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
target.plugins.apply(KotlinPlatformJvmPlugin::class.java) | ||
target.plugins.apply(KtlintConventionPlugin::class.java) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
build-logic/src/main/kotlin/com/squareup/anvil/benchmark/BenchmarkPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.squareup.anvil.benchmark | ||
|
||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
|
||
open class BenchmarkPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
target.tasks.register("createBenchmarkProject", CreateBenchmarkProjectTask::class.java) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"library" is so generic, why not
com.squareup.anvil.library
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my head, I consider local convention plugins to be closely related to precompiled script plugins or built-in plugins. Since the precompiled plugins often have short names and the built-in ones all have short names, I'm mostly convinced that this type of plugin should also have a short name.
It's not something I feel strongly about, though. If you're unconvinced, I can change it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel strongly either. But my first impression was "what's that and where is it coming from". Searching only for "library" also takes longer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will continue to slightly lean in the other direction, but the IDs have now been lengthened.