-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
465 additions
and
614 deletions.
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 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,48 @@ | ||
plugins { | ||
alias libs.plugins.kotlin.jvm | ||
alias libs.plugins.ktlint | ||
id 'java-gradle-plugin' | ||
} | ||
|
||
gradlePlugin { | ||
plugins { | ||
root { | ||
id = "com.squareup.anvil.root" | ||
implementationClass = "com.squareup.anvil.conventions.RootPlugin" | ||
} | ||
library { | ||
id = "com.squareup.anvil.library" | ||
implementationClass = "com.squareup.anvil.conventions.LibraryPlugin" | ||
} | ||
publish { | ||
id = "com.squareup.anvil.publish" | ||
implementationClass = "com.squareup.anvil.conventions.PublishConventionPlugin" | ||
} | ||
itegrationTests { | ||
id = "com.squareup.anvil.itegration-tests" | ||
implementationClass = "com.squareup.anvil.conventions.IntegrationTestsConventionPlugin" | ||
} | ||
} | ||
} | ||
|
||
kotlin { | ||
jvmToolchain { | ||
languageVersion.set(JavaLanguageVersion.of(11)) | ||
} | ||
} | ||
|
||
ktlint { | ||
version = libs.versions.ktlint.get() | ||
} | ||
|
||
dependencies { | ||
compileOnly gradleApi() | ||
|
||
api libs.ktlintRaw | ||
api libs.kotlinpoet | ||
api libs.kgx | ||
|
||
api libs.kotlin.dokka | ||
api libs.kotlin.gradlePlugin | ||
api libs.mavenPublishRaw | ||
} |
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,14 @@ | ||
pluginManagement { | ||
repositories { | ||
google() | ||
gradlePluginPortal() | ||
mavenCentral() | ||
} | ||
includeBuild '../settings' | ||
} | ||
|
||
plugins { | ||
id 'com.squareup.anvil.gradle-settings' | ||
} | ||
|
||
rootProject.name = "conventions" |
File renamed without changes.
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
47 changes: 47 additions & 0 deletions
47
...ogic/conventions/src/main/kotlin/com/squareup/anvil/conventions/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,47 @@ | ||
package com.squareup.anvil.conventions | ||
|
||
import com.rickbusarow.kgx.isRootProject | ||
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.extensions.configure(KtlintExtension::class.java) { ktlint -> | ||
ktlint.version.set(target.libsCatalog.version("ktlint")) | ||
ktlint.verbose.set(true) | ||
} | ||
|
||
if (target.isRootProject() && target.isInMainAnvilBuild()) { | ||
propagateToIncludedBuilds(target) | ||
} | ||
} | ||
|
||
/** | ||
* Make calls to `ktlintCheck` and `ktlintFormat` in the root project propagate to all included | ||
* builds. These two invocations will be equivalent: | ||
* | ||
* ```sh | ||
* ./gradlew ktlintCheck | ||
* ./gradlew ktlintCheck :build-logic:conventions:ktlintCheck :build-logic:settings:ktlintCheck | ||
* ``` | ||
*/ | ||
private fun propagateToIncludedBuilds(target: Project) { | ||
target.gradle.includedBuilds | ||
.filter { it.name != "delegate" } | ||
.forEach { build -> | ||
target.tasks.named("ktlintCheck") { task -> | ||
task.dependsOn(build.task(":ktlintCheck")) | ||
} | ||
target.tasks.named("ktlintFormat") { task -> | ||
task.dependsOn(build.task(":ktlintFormat")) | ||
} | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
build-logic/conventions/src/main/kotlin/com/squareup/anvil/conventions/LibraryPlugin.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,49 @@ | ||
package com.squareup.anvil.conventions | ||
|
||
import com.rickbusarow.kgx.libsCatalog | ||
import com.rickbusarow.kgx.pluginId | ||
import org.gradle.api.Plugin | ||
import org.gradle.api.Project | ||
import org.gradle.plugins.ide.idea.model.IdeaModel | ||
|
||
open class LibraryPlugin : Plugin<Project> { | ||
override fun apply(target: Project) { | ||
|
||
target.plugins.apply(target.libsCatalog.pluginId("kotlin-jvm")) | ||
target.plugins.apply(KtlintConventionPlugin::class.java) | ||
|
||
when (target.path) { | ||
":annotations", | ||
":annotations-optional", | ||
":compiler", | ||
":compiler-api", | ||
":compiler-utils", | ||
":gradle-plugin", | ||
-> target.setBuildDir() | ||
} | ||
} | ||
|
||
private fun Project.setBuildDir() { | ||
|
||
if (file("build").exists()) { | ||
file("build").deleteRecursively() | ||
} | ||
val anvilBuildDir = file("build-anvil") | ||
val delegateDir = file("build-delegate") | ||
|
||
plugins.apply("idea") | ||
// Make both the `build-anvil` and `build-delegate` directories show | ||
// up as build directories within the IDE. | ||
extensions.configure(IdeaModel::class.java) { idea -> | ||
idea.module { module -> | ||
module.excludeDirs.addAll(listOf(delegateDir, anvilBuildDir)) | ||
} | ||
} | ||
|
||
if (isInDelegateBuild()) { | ||
layout.buildDirectory.set(delegateDir) | ||
} else { | ||
layout.buildDirectory.set(anvilBuildDir) | ||
} | ||
} | ||
} |
Oops, something went wrong.