diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6cb607802..6106bc203 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs : check-latest : true - name : KtLint - run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace && ./gradlew -p buildSrc ktlintCheck --no-build-cache --no-daemon --stacktrace + run : ./gradlew ktlintCheck --no-build-cache --no-daemon --stacktrace && ./gradlew -p build-logic ktlintCheck --no-build-cache --no-daemon --stacktrace lint : runs-on : ubuntu-latest diff --git a/annotations-optional/build.gradle b/annotations-optional/build.gradle index 20cfc4a33..2d53f8ab2 100644 --- a/annotations-optional/build.gradle +++ b/annotations-optional/build.gradle @@ -1,10 +1,14 @@ plugins { - alias(libs.plugins.kotlin.jvm) + id 'com.squareup.anvil.library' + id 'com.squareup.anvil.publish' } -apply from: rootProject.file('publishing.gradle') -kotlin { - explicitApi() +publish { + configurePom( + artifactId: 'annotations-optional', + pomName: 'Anvil Optional Annotations', + pomDescription: 'Optional annotations that we\'ve found to be helpful with managing larger dependency graphs' + ) } dependencies { diff --git a/annotations-optional/gradle.properties b/annotations-optional/gradle.properties deleted file mode 100644 index 7e80e29bf..000000000 --- a/annotations-optional/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Optional Annotations -POM_ARTIFACT_ID=annotations-optional -POM_PACKAGING=jar diff --git a/annotations/build.gradle b/annotations/build.gradle index 5f5cd589b..ec6825491 100644 --- a/annotations/build.gradle +++ b/annotations/build.gradle @@ -1,7 +1,15 @@ plugins { - alias(libs.plugins.kotlin.jvm) + id 'com.squareup.anvil.library' + id 'com.squareup.anvil.publish' +} + +publish { + configurePom( + artifactId: 'annotations', + pomName: 'Anvil Annotations', + pomDescription: 'Annotations used to mark classes and methods for code generation in Anvil' + ) } -apply from: rootProject.file('publishing.gradle') kotlin { explicitApi() diff --git a/annotations/gradle.properties b/annotations/gradle.properties deleted file mode 100644 index fd6f470c2..000000000 --- a/annotations/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Annotations -POM_ARTIFACT_ID=annotations -POM_PACKAGING=jar \ No newline at end of file diff --git a/build-logic/build.gradle b/build-logic/build.gradle new file mode 100644 index 000000000..eb73d224f --- /dev/null +++ b/build-logic/build.gradle @@ -0,0 +1,42 @@ +plugins { + alias(libs.plugins.kotlin.jvm) + alias(libs.plugins.ktlint) + id 'java-gradle-plugin' +} + +gradlePlugin { + plugins { + library { + id = "com.squareup.anvil.library" + implementationClass = "com.squareup.anvil.LibraryPlugin" + } + root { + id = "com.squareup.anvil.root" + implementationClass = "com.squareup.anvil.RootPlugin" + } + publish { + id = "com.squareup.anvil.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() +} diff --git a/buildSrc/settings.gradle b/build-logic/settings.gradle similarity index 95% rename from buildSrc/settings.gradle rename to build-logic/settings.gradle index 7d8d3a166..752d661c8 100644 --- a/buildSrc/settings.gradle +++ b/build-logic/settings.gradle @@ -6,6 +6,8 @@ pluginManagement { } } +rootProject.name = "build-logic" + dependencyResolutionManagement { versionCatalogs { Map overrides = new LinkedHashMap() @@ -29,6 +31,7 @@ dependencyResolutionManagement { repositories { google() + gradlePluginPortal() mavenCentral() if (hasProperty("anvil.allowSnapshots")) { maven { url 'https://maven.pkg.jetbrains.space/kotlin/p/kotlin/dev' } diff --git a/build-logic/src/main/kotlin/com/squareup/anvil/KtlintConventionPlugin.kt b/build-logic/src/main/kotlin/com/squareup/anvil/KtlintConventionPlugin.kt new file mode 100644 index 000000000..bc9940e34 --- /dev/null +++ b/build-logic/src/main/kotlin/com/squareup/anvil/KtlintConventionPlugin.kt @@ -0,0 +1,20 @@ +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 { + + 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) + } + } +} diff --git a/build-logic/src/main/kotlin/com/squareup/anvil/PublishConventionPlugin.kt b/build-logic/src/main/kotlin/com/squareup/anvil/PublishConventionPlugin.kt new file mode 100644 index 000000000..661ed3c70 --- /dev/null +++ b/build-logic/src/main/kotlin/com/squareup/anvil/PublishConventionPlugin.kt @@ -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 { + 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) { + + 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) + } + } + } +} diff --git a/build-logic/src/main/kotlin/com/squareup/anvil/RootPlugin.kt b/build-logic/src/main/kotlin/com/squareup/anvil/RootPlugin.kt new file mode 100644 index 000000000..1c5c72b93 --- /dev/null +++ b/build-logic/src/main/kotlin/com/squareup/anvil/RootPlugin.kt @@ -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 { + override fun apply(target: Project) { + target.plugins.apply(BenchmarkPlugin::class.java) + target.plugins.apply(KtlintConventionPlugin::class.java) + } +} + +open class LibraryPlugin : Plugin { + override fun apply(target: Project) { + target.plugins.apply(KotlinPlatformJvmPlugin::class.java) + target.plugins.apply(KtlintConventionPlugin::class.java) + } +} diff --git a/build-logic/src/main/kotlin/com/squareup/anvil/benchmark/BenchmarkPlugin.kt b/build-logic/src/main/kotlin/com/squareup/anvil/benchmark/BenchmarkPlugin.kt new file mode 100644 index 000000000..1f510ce6c --- /dev/null +++ b/build-logic/src/main/kotlin/com/squareup/anvil/benchmark/BenchmarkPlugin.kt @@ -0,0 +1,10 @@ +package com.squareup.anvil.benchmark + +import org.gradle.api.Plugin +import org.gradle.api.Project + +open class BenchmarkPlugin : Plugin { + override fun apply(target: Project) { + target.tasks.register("createBenchmarkProject", CreateBenchmarkProjectTask::class.java) + } +} diff --git a/buildSrc/src/main/kotlin/com/squareup/anvil/benchmark/CreateBenchmarkProjectTask.kt b/build-logic/src/main/kotlin/com/squareup/anvil/benchmark/CreateBenchmarkProjectTask.kt similarity index 100% rename from buildSrc/src/main/kotlin/com/squareup/anvil/benchmark/CreateBenchmarkProjectTask.kt rename to build-logic/src/main/kotlin/com/squareup/anvil/benchmark/CreateBenchmarkProjectTask.kt diff --git a/buildSrc/src/main/kotlin/com/squareup/anvil/benchmark/Module.kt b/build-logic/src/main/kotlin/com/squareup/anvil/benchmark/Module.kt similarity index 100% rename from buildSrc/src/main/kotlin/com/squareup/anvil/benchmark/Module.kt rename to build-logic/src/main/kotlin/com/squareup/anvil/benchmark/Module.kt diff --git a/build.gradle b/build.gradle index 5648b39a3..a2ab6aa4d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,11 +1,9 @@ -import com.squareup.anvil.benchmark.CreateBenchmarkProjectTask import org.gradle.api.internal.project.DefaultProject import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile buildscript { dependencies { - classpath libs.mavenPublishRaw classpath("com.squareup.anvil:gradle-plugin:${findProperty("VERSION_NAME")}",) } } @@ -13,13 +11,15 @@ buildscript { plugins { alias(libs.plugins.agp.application) apply false alias(libs.plugins.agp.library) apply false - alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.gradlePublish) apply false alias(libs.plugins.kotlin.android) apply false - alias(libs.plugins.kotlin.kapt) apply false alias(libs.plugins.kotlin.dokka) apply false + alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.kapt) apply false alias(libs.plugins.kotlin.multiplatform) apply false - alias(libs.plugins.gradlePublish) apply false alias(libs.plugins.ktlint) apply false + alias(libs.plugins.mavenPublishBase) apply false + id 'com.squareup.anvil.root' } boolean isCi = (System.getenv('CI') ?: 'false').toBoolean() @@ -40,14 +40,6 @@ println "Versions: " + [ boolean configureOnDemandEnabled = getProperty("org.gradle.configureondemand", "false").toBoolean() subprojects { - if (buildFile.exists()) { - apply plugin: 'org.jlleitschuh.gradle.ktlint' - - ktlint { - version = libs.versions.ktlint.get() - verbose = true - } - } tasks.withType(Test).configureEach { testLogging { @@ -129,13 +121,13 @@ subprojects { } } -task clean(type: Delete) { - delete rootProject.buildDir +// For any publish task invoked in the main build, there's a corresponding task in the gradle-plugin +// included build. Gradle doesn't invoke those included build tasks when the main build's tasks are +// run, and that's annoying. This fixes that behavior. +tasks.withType(PublishToMavenRepository).configureEach { mainTask -> + mainTask.dependsOn(gradle.includedBuild("gradle-plugin").task(":${mainTask.name}")) } def getProperty(String name, String defaultValue) { return project.hasProperty(name) ? project.getProperty(name) : defaultValue } - -// Register the task that can create the benchmark project. -tasks.register("createBenchmarkProject", CreateBenchmarkProjectTask) diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle deleted file mode 100644 index 3a22c37f9..000000000 --- a/buildSrc/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.ktlint) -} - -kotlin { - jvmToolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } -} - -dependencies { - compileOnly(gradleApi()) - implementation libs.kotlinpoet -} - -ktlint { - version = libs.versions.ktlint.get() -} diff --git a/compiler-api/build.gradle b/compiler-api/build.gradle index febb12209..9ba2cf149 100644 --- a/compiler-api/build.gradle +++ b/compiler-api/build.gradle @@ -1,7 +1,15 @@ plugins { - alias(libs.plugins.kotlin.jvm) + id 'com.squareup.anvil.library' + id 'com.squareup.anvil.publish' +} + +publish { + configurePom( + artifactId: 'compiler-api', + pomName: 'Anvil Compiler API', + pomDescription: 'API definitions for creating custom code generators that integrate with Anvil' + ) } -apply from: rootProject.file('publishing.gradle') kotlin { explicitApi() diff --git a/compiler-api/gradle.properties b/compiler-api/gradle.properties deleted file mode 100644 index 50db545ef..000000000 --- a/compiler-api/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Compiler API -POM_ARTIFACT_ID=compiler-api -POM_PACKAGING=jar diff --git a/compiler-utils/build.gradle b/compiler-utils/build.gradle index 84776ffac..e0c3f9bcb 100644 --- a/compiler-utils/build.gradle +++ b/compiler-utils/build.gradle @@ -1,13 +1,18 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - alias(libs.plugins.kotlin.jvm) + id 'com.squareup.anvil.library' id 'java-test-fixtures' + id 'com.squareup.anvil.publish' } -apply from: rootProject.file('publishing.gradle') -kotlin { - explicitApi() +publish { + configurePom( + artifactId: "compiler-utils", + pomName: "Anvil Compiler Utils", + pomDescription: 'Optional utility and extension functions for working with PSI and descriptors, ' + + 'designed to simplify code generation tasks in Anvil' + ) } def isIdeSync = getSystemProperty('idea.sync.active', 'false').toBoolean() @@ -58,4 +63,3 @@ private def getSystemProperty(String name, String defaultValue = null) { return provider.getOrNull() } } - diff --git a/compiler-utils/gradle.properties b/compiler-utils/gradle.properties deleted file mode 100644 index bbbbbfded..000000000 --- a/compiler-utils/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Compiler Utils -POM_ARTIFACT_ID=compiler-utils -POM_PACKAGING=jar diff --git a/compiler/build.gradle b/compiler/build.gradle index 5f608f50c..f61455962 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -1,12 +1,29 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.kotlin.kapt) + id 'com.squareup.anvil.library' + alias libs.plugins.kotlin.kapt + alias libs.plugins.buildconfig + id 'com.squareup.anvil.publish' } -apply from: rootProject.file('publishing.gradle') -apply from: project.file('generate_build_properties.gradle') +buildConfig { + className('BuildProperties') + packageName('com.squareup.anvil.compiler') + useKotlinOutput { topLevelConstants = true } + + buildConfigField('boolean', 'WARNINGS_AS_ERRORS',"${rootProject.ext.warningsAsErrors}") + buildConfigField('boolean', 'FULL_TEST_RUN', "${libs.versions.config.fullTestRun.get()}") +} + +publish { + configurePom( + artifactId: 'compiler', + pomName: 'Anvil Compiler', + pomDescription: 'The core implementation module for Anvil, responsible for hooking into ' + + 'the Kotlin compiler and orchestrating code generation' + ) +} dependencies { implementation project(':annotations') @@ -34,6 +51,11 @@ dependencies { testImplementation libs.truth } +// Fixes: +// Reason: Task ':compiler:dokkaHtml' uses this output of task ':compiler:kaptKotlin' +// without declaring an explicit or implicit dependency. +tasks.named("dokkaHtml") { mustRunAfter("kaptKotlin") } + tasks.withType(KotlinCompile).configureEach { compilerOptions { // The flag is needed because we extend an interface that uses @JvmDefault and the Kotlin diff --git a/compiler/generate_build_properties.gradle b/compiler/generate_build_properties.gradle deleted file mode 100644 index b8d82609f..000000000 --- a/compiler/generate_build_properties.gradle +++ /dev/null @@ -1,40 +0,0 @@ -def generatedDirPath = 'generated/sources/build-properties/kotlin/main' - -sourceSets { - test.java.srcDirs += "$buildDir/$generatedDirPath" -} - -def warningsAsErrors = rootProject.ext.warningsAsErrors - -def generateBuildProperties = project.tasks.register('generateBuildProperties') { - File buildPropertiesFile = layout.buildDirectory.file(generatedDirPath + '/BuildProperties.kt') - .get().asFile - - def fullTestRun = libs.versions.config.fullTestRun.get() - - inputs.property 'fullTestRun', fullTestRun - inputs.property 'kotlinVersion', libs.versions.kotlin.get() - inputs.property 'warningsAsErrors', warningsAsErrors - - outputs.file buildPropertiesFile - - doLast { - buildPropertiesFile.parentFile.mkdirs() - buildPropertiesFile.write """\ - package com.squareup.anvil.compiler - - internal const val WARNINGS_AS_ERRORS = $warningsAsErrors - - internal const val FULL_TEST_RUN = $fullTestRun - """.stripIndent() - } -} - -tasks.named("compileKotlin").configure { - it.dependsOn generateBuildProperties -} - -// So Gradle stops complaining about the missing dependency -tasks.named("runKtlintCheckOverTestSourceSet").configure { - it.dependsOn generateBuildProperties -} diff --git a/compiler/gradle.properties b/compiler/gradle.properties deleted file mode 100644 index bd1a93954..000000000 --- a/compiler/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Compiler -POM_ARTIFACT_ID=compiler -POM_PACKAGING=jar \ No newline at end of file diff --git a/gradle-plugin/build.gradle b/gradle-plugin/build.gradle index 4505ba9e5..8a6821875 100644 --- a/gradle-plugin/build.gradle +++ b/gradle-plugin/build.gradle @@ -1,77 +1,46 @@ -buildscript { - repositories { - google() - gradlePluginPortal() - mavenCentral() - } - - dependencies { - classpath libs.kotlin.dokka - classpath libs.kotlin.gradlePlugin - classpath libs.mavenPublishRaw - classpath libs.gradlePublishRaw - classpath libs.ktlintRaw - } +plugins { + id 'com.squareup.anvil.library' + alias libs.plugins.gradlePublish + alias libs.plugins.buildconfig + id 'java-gradle-plugin' + id 'com.squareup.anvil.publish' } -apply from: rootProject.file('copy_properties.gradle') +buildConfig { + className('BuildProperties') + packageName('com.squareup.anvil.plugin') + useKotlinOutput { topLevelConstants = true } -apply plugin: 'java-gradle-plugin' -apply plugin: 'org.jetbrains.kotlin.jvm' -apply plugin: 'com.gradle.plugin-publish' -apply plugin: 'org.jlleitschuh.gradle.ktlint' + buildConfigField('String', 'GROUP', "\"$GROUP\"") + buildConfigField('String', 'VERSION', "\"$VERSION_NAME\"") +} -apply from: rootProject.file('generate_build_properties.gradle') -apply from: rootProject.file('../publishing.gradle') +def pomName = 'Anvil Gradle Plugin' +def pomDescription = 'A Kotlin compiler plugin to make dependency injection with Dagger 2 ' + + 'easier by automatically merging Dagger modules and component interfaces.' -// Pull from the GROUP property and assign to the project -group = GROUP +publish { + configurePom( + artifactId: 'gradle-plugin', + pomName: pomName, + pomDescription: pomDescription + ) +} gradlePlugin { + website = project.findProperty('POM_URL') as String + vcsUrl = project.findProperty('POM_SCM_URL') as String plugins { anvilPlugin { id = "com.squareup.anvil" - displayName = project.findProperty('POM_NAME') + displayName = pomName implementationClass = "com.squareup.anvil.plugin.AnvilPlugin" - description = project.findProperty('POM_DESCRIPTION') + description = pomDescription + tags.addAll('dagger2', 'dagger2-android', 'kotlin', 'kotlin-compiler-plugin') } } } -pluginBundle { - website = project.findProperty('POM_URL') - vcsUrl = project.findProperty('POM_SCM_URL') - tags = ['dagger2', 'dagger2-android', 'kotlin', 'kotlin-compiler-plugin'] -} - -// Use JDK 11 but target Java 8 for maximum compatibility. -java { - toolchain { - languageVersion.set(JavaLanguageVersion.of(11)) - } -} - -tasks.withType(JavaCompile).configureEach { - options.release.set(8) -} - -tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach { - compilerOptions { - jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8) - - // Because Gradle hardcodes Kotlin versions we have warnings during compilation. - allWarningsAsErrors = false - } -} - -kotlin { - explicitApi() -} - -ktlint { - version = libs.versions.ktlint.get() -} - dependencies { // Necessary to bump a transitive dependency. compileOnly libs.kotlin.reflect diff --git a/gradle-plugin/generate_build_properties.gradle b/gradle-plugin/generate_build_properties.gradle deleted file mode 100644 index b02cde2d5..000000000 --- a/gradle-plugin/generate_build_properties.gradle +++ /dev/null @@ -1,64 +0,0 @@ -// The Kotlin subplugin wants to know the version and group of the Kotlin compiler plugin artifact -// before it gives us a Project to retrieve the value from Gradle properties. This workaround -// generates a Kotlin file that becomes part of the source set and contains necessary values. - -def generatedDirPath = 'generated/sources/build-properties/kotlin/main' - -sourceSets { - main.java.srcDirs += "$buildDir/$generatedDirPath" -} - -def generateBuildProperties = project.tasks.register('generateBuildProperties') { - def version = getProperty('VERSION_NAME').toString() - def group = getProperty('GROUP').toString() - - File buildPropertiesFile = layout.buildDirectory.file(generatedDirPath + '/BuildProperties.kt') - .get().asFile - - inputs.property 'version', version - inputs.property 'group', group - - outputs.file buildPropertiesFile - - doLast { - buildPropertiesFile.parentFile.mkdirs() - buildPropertiesFile.write """\ - package com.squareup.anvil.plugin - - internal const val VERSION = "$version" - internal const val GROUP = "$group" - """.stripIndent() - } -} - -compileKotlin { - dependsOn generateBuildProperties -} - -// Add the task dependencies to enforce correct ordering when depending out outputs. Requires to be -// lazy, because *SourcesJar seems to be registered in a later lifecycle. -def taskNames = [ - 'dokkaHtml', - 'publishPluginJar', - 'runKtlintCheckOverMainSourceSet', - 'javaSourcesJar', - 'kotlinSourcesJar', -] - -afterEvaluate { - taskNames.each { taskName -> - try { - tasks.named(taskName).configure { - it.dependsOn(generateBuildProperties) - } - } catch (UnknownTaskException ignored) { - } - } - - // javaSourcesJar is registered even later. Gradle is love. - tasks.whenTaskAdded { Task task -> - if (taskNames.contains(task.name)) { - task.dependsOn(generateBuildProperties) - } - } -} diff --git a/gradle-plugin/gradle.properties b/gradle-plugin/gradle.properties deleted file mode 100644 index 7e2199b88..000000000 --- a/gradle-plugin/gradle.properties +++ /dev/null @@ -1,3 +0,0 @@ -POM_NAME=Anvil Gradle Plugin -POM_ARTIFACT_ID=gradle-plugin -POM_PACKAGING=jar \ No newline at end of file diff --git a/gradle-plugin/gradle.properties b/gradle-plugin/gradle.properties new file mode 120000 index 000000000..7677fb73b --- /dev/null +++ b/gradle-plugin/gradle.properties @@ -0,0 +1 @@ +../gradle.properties \ No newline at end of file diff --git a/gradle-plugin/settings.gradle b/gradle-plugin/settings.gradle index 233bc27ab..207c21fc0 100644 --- a/gradle-plugin/settings.gradle +++ b/gradle-plugin/settings.gradle @@ -4,6 +4,8 @@ pluginManagement { gradlePluginPortal() mavenCentral() } + + includeBuild('../build-logic') } dependencyResolutionManagement { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index be9f80f84..c14c11123 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -11,18 +11,20 @@ agp = "7.3.1" autoService = "1.1.1" autoValue = "1.10.1" +buildconfig = "4.1.2" dagger = "2.46.1" dokka = "1.8.20" espresso = "3.5.1" -gradlePublish = "0.15.0" -kotlin = "1.9.10" +gradlePublish = "1.2.1" kct = "0.3.1" +kgx = "0.1.7" +kotlin = "1.9.10" kotlinpoet = "1.14.2" # If updating KSP version, we currently have ksp override logic in settings.gradle that needs to be updated too ksp = "1.9.10-1.0.13" ktlint = "0.41.0" -ktlintPlugin = "10.2.0" -mavenPublish = "0.18.0" +ktlintPlugin = "11.3.2" +mavenPublish = "0.25.3" # # Configs that we can override in CI. Not exactly "versions" but useful to repurpose it here. @@ -37,6 +39,7 @@ config-generateDaggerFactoriesWithAnvil = "true" [plugins] agp-application = { id = "com.android.application", version.ref = "agp" } agp-library = { id = "com.android.library", version.ref = "agp" } +buildconfig = { id = "com.github.gmazzo.buildconfig", version.ref = "buildconfig" } gradlePublish = { id = "com.gradle.plugin-publish", version.ref = "gradlePublish" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } @@ -45,7 +48,7 @@ kotlin-kapt = { id = "org.jetbrains.kotlin.kapt", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintPlugin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } +mavenPublishBase = { id = "com.vanniktech.maven.publish.base", version.ref = "mavenPublish" } [libraries] androidx-appcompat = "androidx.appcompat:appcompat:1.1.0" @@ -87,6 +90,8 @@ kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test-junit", version.ref = kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" } +kgx = { module = "com.rickbusarow.kgx:kotlin-gradle-extensions", version.ref = "kgx" } + ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } ksp-compilerPlugin = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" } ksp-gradlePlugin = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" } diff --git a/publishing.gradle b/publishing.gradle deleted file mode 100644 index 2b6f025ec..000000000 --- a/publishing.gradle +++ /dev/null @@ -1,8 +0,0 @@ -apply plugin: 'com.vanniktech.maven.publish' -apply plugin: 'org.jetbrains.dokka' - -plugins.withId("com.vanniktech.maven.publish") { - mavenPublish { - sonatypeHost = "S01" - } -} diff --git a/settings.gradle b/settings.gradle index c8e411fb5..e8aca3edb 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,6 +4,8 @@ pluginManagement { gradlePluginPortal() mavenCentral() } + + includeBuild('build-logic') } dependencyResolutionManagement {