From d306eaef93e778ddcc5c85f0016668e049313eba Mon Sep 17 00:00:00 2001 From: Baptiste Candellier Date: Fri, 6 May 2022 20:11:28 +0200 Subject: [PATCH] chore: migrate to gradle.kts, clean up build scripts (#21) --- build.gradle | 55 --------- build.gradle.kts | 84 ++++++++++++++ deps.gradle | 26 ----- gradle/gradle-mvn-push.gradle | 109 ------------------ gradle/libs.versions.toml | 14 +++ gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 7 -- settings.gradle.kts | 15 +++ toothpick-compiler-ksp-core/build.gradle | 30 ----- toothpick-compiler-ksp-core/build.gradle.kts | 22 ++++ toothpick-compiler-ksp-factory/build.gradle | 36 ------ .../build.gradle.kts | 28 +++++ .../build.gradle | 36 ------ .../build.gradle.kts | 28 +++++ toothpick-compiler-ksp/build.gradle | 31 ----- toothpick-compiler-ksp/build.gradle.kts | 23 ++++ toothpick-compiler-test/build.gradle | 24 ---- toothpick-compiler-test/build.gradle.kts | 17 +++ 18 files changed, 232 insertions(+), 355 deletions(-) delete mode 100644 build.gradle create mode 100644 build.gradle.kts delete mode 100644 deps.gradle delete mode 100644 gradle/gradle-mvn-push.gradle create mode 100644 gradle/libs.versions.toml delete mode 100644 settings.gradle create mode 100644 settings.gradle.kts delete mode 100644 toothpick-compiler-ksp-core/build.gradle create mode 100644 toothpick-compiler-ksp-core/build.gradle.kts delete mode 100644 toothpick-compiler-ksp-factory/build.gradle create mode 100644 toothpick-compiler-ksp-factory/build.gradle.kts delete mode 100644 toothpick-compiler-ksp-memberinjector/build.gradle create mode 100644 toothpick-compiler-ksp-memberinjector/build.gradle.kts delete mode 100644 toothpick-compiler-ksp/build.gradle create mode 100644 toothpick-compiler-ksp/build.gradle.kts delete mode 100644 toothpick-compiler-test/build.gradle create mode 100644 toothpick-compiler-test/build.gradle.kts diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 376c9a80..00000000 --- a/build.gradle +++ /dev/null @@ -1,55 +0,0 @@ -buildscript { - apply from: 'deps.gradle' - repositories { - google() - mavenCentral() - } - - dependencies { - classpath deps.kotlin_plugin - classpath deps.kotlin_kover - classpath deps.spotlessPlugin - } -} - -apply plugin: 'kover' - -repositories { - mavenCentral() -} - -subprojects { project -> - group = GROUP - version = VERSION_NAME - - repositories { - mavenCentral() - } - - apply plugin: 'maven-publish' - apply plugin: 'com.diffplug.spotless' - - tasks.withType(JavaCompile) { - options.compilerArgs << '-Xlint:unchecked' - options.deprecation = true - } - - spotless { - kotlin { - // optionally takes a version - ktlint() - target '**/*.kt' - - // also supports license headers - licenseHeaderFile rootProject.file('spotless.license.java.txt') - } - } - - afterEvaluate { - tasks.withType(Test) { - testLogging { - events "passed", "skipped", "failed" - } - } - } -} diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 00000000..1aa6a72c --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,84 @@ +import com.diffplug.gradle.spotless.SpotlessExtension + +plugins { + id("org.jetbrains.kotlinx.kover") version "0.5.0" + id("com.diffplug.gradle.spotless") version "6.2.0" apply false + id("org.jetbrains.kotlin.jvm") version "1.6.10" apply false +} + +subprojects { + pluginManager.apply("com.diffplug.spotless") + + configure { + kotlin { + ktlint() + licenseHeaderFile(rootProject.file("spotless.license.java.txt")) + } + + kotlinGradle { + ktlint() + target("*.gradle.kts") + } + } + + afterEvaluate { + tasks.withType { + testLogging { + events("passed", "skipped", "failed") + } + } + } + + pluginManager.withPlugin("maven-publish") { + apply() + + version = extra["VERSION_NAME"] as String + group = extra["GROUP"] as String + + configure { + withSourcesJar() + withJavadocJar() + } + + configure { + publications { + create("maven") { + from(components["java"]) + + groupId = extra["GROUP"] as String + artifactId = extra["POM_ARTIFACT_ID"] as String + version = extra["VERSION_NAME"] as String + + pom { + packaging = extra["POM_PACKAGING"] as String + + name.set(extra["POM_NAME"] as String) + description.set(extra["POM_DESCRIPTION"] as String) + url.set(extra["POM_URL"] as String) + + scm { + url.set(extra["POM_SCM_URL"] as String) + connection.set(extra["POM_SCM_CONNECTION"] as String) + developerConnection.set(extra["POM_SCM_DEV_CONNECTION"] as String) + } + + licenses { + license { + name.set(extra["POM_LICENCE_NAME"] as String) + url.set(extra["POM_LICENCE_URL"] as String) + distribution.set(extra["POM_LICENCE_DIST"] as String) + } + } + + developers { + developer { + id.set(extra["POM_DEVELOPER_ID"] as String) + name.set(extra["POM_DEVELOPER_NAME"] as String) + } + } + } + } + } + } + } +} diff --git a/deps.gradle b/deps.gradle deleted file mode 100644 index beffabdc..00000000 --- a/deps.gradle +++ /dev/null @@ -1,26 +0,0 @@ -ext.deps = [ - // Common - inject : 'javax.inject:javax.inject:1', - - // Compiler - kotlinpoet : 'com.squareup:kotlinpoet:1.10.2', - kotlinpoet_ksp : 'com.squareup:kotlinpoet-ksp:1.10.2', - ksp : 'com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.4', - - // Kotlin - kotlin_plugin : 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10', - kotlin_kover : 'org.jetbrains.kotlinx.kover:org.jetbrains.kotlinx.kover.gradle.plugin:0.5.0-RC2', - - // TP artifacts - tp : 'com.github.stephanenicolas.toothpick:toothpick:3.1.0', - - // Test dependencies - junit4 : 'junit:junit:4.13-beta-3', - compiletesting_kt : 'com.github.tschuchortdev:kotlin-compile-testing:1.4.7', - compiletesting_ksp: 'com.github.tschuchortdev:kotlin-compile-testing-ksp:1.4.7', - mockito : 'org.mockito:mockito-core:2.4.0', - mockito_kotlin : 'com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0', - - //build - spotlessPlugin : 'com.diffplug.spotless:spotless-plugin-gradle:6.2.0', -] diff --git a/gradle/gradle-mvn-push.gradle b/gradle/gradle-mvn-push.gradle deleted file mode 100644 index 691156e8..00000000 --- a/gradle/gradle-mvn-push.gradle +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright 2013 Chris Banes - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -apply plugin: 'maven-publish' - -version = VERSION_NAME -group = GROUP - -def isReleaseBuild() { - return VERSION_NAME.contains("SNAPSHOT") == false -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : "" -} - -tasks { - task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier.set('sources') - from sourceSets.main.allSource - } - - artifacts { - archives sourcesJar - } -} - -allprojects { - tasks.withType(Javadoc) { - options.addStringOption('Xdoclint:none', '-quiet') - } -} - -publishing { - repositories { - maven { - url = isReleaseBuild() ? getSnapshotRepositoryUrl() : getReleaseRepositoryUrl() - credentials { - username = getRepositoryUsername() - password = getRepositoryPassword() - } - } - } - - publications { - maven(MavenPublication) { - groupId = GROUP - artifactId = POM_ARTIFACT_ID - version = VERSION_NAME - - pom { - name = POM_NAME - packaging = POM_PACKAGING - description = POM_DESCRIPTION - url = POM_URL - - scm { - url = POM_SCM_URL - connection = POM_SCM_CONNECTION - developerConnection = POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name = POM_LICENCE_NAME - url = POM_LICENCE_URL - distribution = POM_LICENCE_DIST - } - } - - developers { - developer { - id = POM_DEVELOPER_ID - name = POM_DEVELOPER_NAME - } - } - } - - from components.java - } - } -} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 00000000..93c29f30 --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,14 @@ +[libraries] +inject = "javax.inject:javax.inject:1" + +kotlinpoet-core = "com.squareup:kotlinpoet:1.10.2" +kotlinpoet-ksp = "com.squareup:kotlinpoet-ksp:1.10.2" +ksp = "com.google.devtools.ksp:symbol-processing-api:1.6.10-1.0.4" + +tp = "com.github.stephanenicolas.toothpick:toothpick:3.1.0" + +junit4 = "junit:junit:4.13-beta-3" +compiletesting-kt = "com.github.tschuchortdev:kotlin-compile-testing:1.4.7" +compiletesting-ksp = "com.github.tschuchortdev:kotlin-compile-testing-ksp:1.4.7" +mockito = "org.mockito:mockito-core:2.4.0" +mockito_kotlin = "com.nhaarman.mockitokotlin2:mockito-kotlin:2.1.0" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 669386b8..92f06b50 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle deleted file mode 100644 index 325d5e99..00000000 --- a/settings.gradle +++ /dev/null @@ -1,7 +0,0 @@ -include ':toothpick-compiler-ksp' -include ':toothpick-compiler-ksp-core' -include ':toothpick-compiler-ksp-factory' -include ':toothpick-compiler-ksp-memberinjector' -include ':toothpick-compiler-test' - -rootProject.name = 'toothpick-parent' diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 00000000..ba4de061 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,15 @@ +rootProject.name = "toothpick-compiler-ksp-parent" + +include(":toothpick-compiler-ksp") +include(":toothpick-compiler-ksp-core") +include(":toothpick-compiler-ksp-factory") +include(":toothpick-compiler-ksp-memberinjector") +include(":toothpick-compiler-test") + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + google() + mavenCentral() + } +} diff --git a/toothpick-compiler-ksp-core/build.gradle b/toothpick-compiler-ksp-core/build.gradle deleted file mode 100644 index 8150cf87..00000000 --- a/toothpick-compiler-ksp-core/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -dependencies { - api deps.inject - api deps.tp - - implementation deps.ksp - - implementation deps.kotlinpoet - implementation deps.kotlinpoet_ksp -} - -apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/toothpick-compiler-ksp-core/build.gradle.kts b/toothpick-compiler-ksp-core/build.gradle.kts new file mode 100644 index 00000000..d13aea5c --- /dev/null +++ b/toothpick-compiler-ksp-core/build.gradle.kts @@ -0,0 +1,22 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.kotlin.jvm") + `maven-publish` +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + api(libs.inject) + api(libs.tp) + + implementation(libs.ksp) + + implementation(libs.kotlinpoet.core) + implementation(libs.kotlinpoet.ksp) +} diff --git a/toothpick-compiler-ksp-factory/build.gradle b/toothpick-compiler-ksp-factory/build.gradle deleted file mode 100644 index f15efcb6..00000000 --- a/toothpick-compiler-ksp-factory/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -dependencies { - api deps.inject - api deps.tp - - implementation project(':toothpick-compiler-ksp-core') - - implementation deps.ksp - - implementation deps.kotlinpoet - implementation deps.kotlinpoet_ksp - - testImplementation project(':toothpick-compiler-test') - testImplementation deps.junit4 - testImplementation deps.compiletesting_kt -} - -apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/toothpick-compiler-ksp-factory/build.gradle.kts b/toothpick-compiler-ksp-factory/build.gradle.kts new file mode 100644 index 00000000..9241ed95 --- /dev/null +++ b/toothpick-compiler-ksp-factory/build.gradle.kts @@ -0,0 +1,28 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.kotlin.jvm") + `maven-publish` +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + api(libs.inject) + api(libs.tp) + + implementation(project(":toothpick-compiler-ksp-core")) + + implementation(libs.ksp) + + implementation(libs.kotlinpoet.core) + implementation(libs.kotlinpoet.ksp) + + testImplementation(project(":toothpick-compiler-test")) + testImplementation(libs.junit4) + testImplementation(libs.compiletesting.kt) +} diff --git a/toothpick-compiler-ksp-memberinjector/build.gradle b/toothpick-compiler-ksp-memberinjector/build.gradle deleted file mode 100644 index f15efcb6..00000000 --- a/toothpick-compiler-ksp-memberinjector/build.gradle +++ /dev/null @@ -1,36 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -dependencies { - api deps.inject - api deps.tp - - implementation project(':toothpick-compiler-ksp-core') - - implementation deps.ksp - - implementation deps.kotlinpoet - implementation deps.kotlinpoet_ksp - - testImplementation project(':toothpick-compiler-test') - testImplementation deps.junit4 - testImplementation deps.compiletesting_kt -} - -apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/toothpick-compiler-ksp-memberinjector/build.gradle.kts b/toothpick-compiler-ksp-memberinjector/build.gradle.kts new file mode 100644 index 00000000..9241ed95 --- /dev/null +++ b/toothpick-compiler-ksp-memberinjector/build.gradle.kts @@ -0,0 +1,28 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.kotlin.jvm") + `maven-publish` +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + api(libs.inject) + api(libs.tp) + + implementation(project(":toothpick-compiler-ksp-core")) + + implementation(libs.ksp) + + implementation(libs.kotlinpoet.core) + implementation(libs.kotlinpoet.ksp) + + testImplementation(project(":toothpick-compiler-test")) + testImplementation(libs.junit4) + testImplementation(libs.compiletesting.kt) +} diff --git a/toothpick-compiler-ksp/build.gradle b/toothpick-compiler-ksp/build.gradle deleted file mode 100644 index 54ff8fff..00000000 --- a/toothpick-compiler-ksp/build.gradle +++ /dev/null @@ -1,31 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -dependencies { - implementation project(":toothpick-compiler-ksp-factory") - implementation project(":toothpick-compiler-ksp-memberinjector") - - implementation deps.ksp - - testImplementation project(':toothpick-compiler-test') - testImplementation deps.junit4 - testImplementation deps.compiletesting_kt -} - -apply from: rootProject.file('gradle/gradle-mvn-push.gradle') diff --git a/toothpick-compiler-ksp/build.gradle.kts b/toothpick-compiler-ksp/build.gradle.kts new file mode 100644 index 00000000..0df2a7b6 --- /dev/null +++ b/toothpick-compiler-ksp/build.gradle.kts @@ -0,0 +1,23 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.kotlin.jvm") + `maven-publish` +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + implementation(project(":toothpick-compiler-ksp-factory")) + implementation(project(":toothpick-compiler-ksp-memberinjector")) + + implementation(libs.ksp) + + testImplementation(project(":toothpick-compiler-test")) + testImplementation(libs.junit4) + testImplementation(libs.compiletesting.kt) +} diff --git a/toothpick-compiler-test/build.gradle b/toothpick-compiler-test/build.gradle deleted file mode 100644 index 58cc79ba..00000000 --- a/toothpick-compiler-test/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -plugins { - id 'org.jetbrains.kotlin.jvm' -} - -sourceCompatibility = 1.8 -targetCompatibility = 1.8 - -compileKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = "1.8" - } -} - -dependencies { - implementation deps.junit4 - implementation deps.compiletesting_kt - implementation deps.compiletesting_ksp -} diff --git a/toothpick-compiler-test/build.gradle.kts b/toothpick-compiler-test/build.gradle.kts new file mode 100644 index 00000000..cfd38752 --- /dev/null +++ b/toothpick-compiler-test/build.gradle.kts @@ -0,0 +1,17 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("org.jetbrains.kotlin.jvm") +} + +tasks.withType { + kotlinOptions { + jvmTarget = "1.8" + } +} + +dependencies { + implementation(libs.junit4) + implementation(libs.compiletesting.kt) + implementation(libs.compiletesting.ksp) +}