diff --git a/build.gradle.kts b/build.gradle.kts index 8fd4ff9..da6f019 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,49 +1,6 @@ -allprojects { - repositories { - mavenCentral() - } - - group = "com.github.serras.kopykat" - version = "0.1" +plugins { + buildsrc.conventions.`kopykat-base` } -subprojects { - apply(plugin = "java-library") - apply(plugin = "maven-publish") - - configure { - publications { - create("maven") { - groupId = project.group as String - artifactId = project.name - version = project.version as String - from(components["java"]) - - pom { - description.set("Little utilities for more pleasant immutable data in Kotlin") - url.set("https://github.com/serras/kopykat") - licenses { - - } - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - developers { - developer { - id.set("kopykat-authors") - name.set("The KopyKat authors") - } - } - scm { - connection.set("scm:git:git://github.com/serras/kopykat.git") - developerConnection.set("scm:git:ssh://git@github.com/serras/kopykat.git") - url.set("https://github.com/serras/kopykat") - } - } - } - } - } -} +group = "com.github.serras.kopykat" +version = "0.1" diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..6673d03 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,41 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + `kotlin-dsl` + kotlin("jvm") version embeddedKotlinVersion +} + +val gradleJvmTarget = "11" +val gradleKotlinTarget = "1.6" + +val kotlinVersion = "1.7.10" + +dependencies { + implementation(platform(libs.kotlin.bom)) + + // Set the *Maven coordinates* of Gradle plugins here. + // This should be the only place where Gradle plugins versions are defined. + + implementation(libs.gradlePlugin.kotlinJvm) +} + + +tasks.withType().configureEach { + kotlinOptions { + jvmTarget = gradleJvmTarget + apiVersion = gradleKotlinTarget + languageVersion = gradleKotlinTarget + } +} + + +kotlin { + jvmToolchain { + (this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(gradleJvmTarget)) + } +} + + +kotlinDslPluginOptions { + jvmTarget.set(gradleJvmTarget) +} diff --git a/buildSrc/repositories.settings.gradle.kts b/buildSrc/repositories.settings.gradle.kts new file mode 100644 index 0000000..ee4a34e --- /dev/null +++ b/buildSrc/repositories.settings.gradle.kts @@ -0,0 +1,24 @@ +// shared repository definitions for both the main project and buildSrc + +@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS) + + repositories { + mavenCentral() + jitpack() + gradlePluginPortal() + } + + pluginManagement { + repositories { + gradlePluginPortal() + mavenCentral() + jitpack() + } + } +} + +fun RepositoryHandler.jitpack() { + maven("https://jitpack.io") +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..5c7ba0e --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,12 @@ +rootProject.name = "buildSrc" + +apply(from = "./repositories.settings.gradle.kts") + +@Suppress("UnstableApiUsage") // Central declaration of repositories is an incubating feature +dependencyResolutionManagement { + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} diff --git a/buildSrc/src/main/kotlin/buildsrc/conventions/kopykat-base.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/conventions/kopykat-base.gradle.kts new file mode 100644 index 0000000..7879686 --- /dev/null +++ b/buildSrc/src/main/kotlin/buildsrc/conventions/kopykat-base.gradle.kts @@ -0,0 +1,12 @@ +package buildsrc.conventions + +plugins { + base +} + +description = "Common config that can be used in all projects" + +if (project != rootProject) { + project.group = rootProject.group + project.version = rootProject.version +} diff --git a/buildSrc/src/main/kotlin/buildsrc/conventions/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/conventions/kotlin-jvm.gradle.kts new file mode 100644 index 0000000..0eaa374 --- /dev/null +++ b/buildSrc/src/main/kotlin/buildsrc/conventions/kotlin-jvm.gradle.kts @@ -0,0 +1,28 @@ +package buildsrc.conventions + +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + +plugins { + id("buildsrc.conventions.kopykat-base") + kotlin("jvm") + `java-library` +} + +dependencies { + implementation(platform(kotlin("bom"))) +} + +kotlin { + explicitApi() + jvmToolchain { + languageVersion.set(JavaLanguageVersion.of("11")) + } +} + +tasks.test { + useJUnitPlatform() +} + +tasks.withType().configureEach { + kotlinOptions.jvmTarget = "1.8" +} diff --git a/buildSrc/src/main/kotlin/buildsrc/conventions/maven-publish.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/conventions/maven-publish.gradle.kts new file mode 100644 index 0000000..1c9161c --- /dev/null +++ b/buildSrc/src/main/kotlin/buildsrc/conventions/maven-publish.gradle.kts @@ -0,0 +1,43 @@ +package buildsrc.conventions + +plugins { + `maven-publish` +} + +publishing { + // configure all publications to have the same POM + publications.withType().configureEach { + pom { + description.set("Little utilities for more pleasant immutable data in Kotlin") + url.set("https://github.com/serras/kopykat") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("kopykat-authors") + name.set("The KopyKat authors") + } + } + scm { + connection.set("scm:git:git://github.com/serras/kopykat.git") + developerConnection.set("scm:git:ssh://git@github.com/serras/kopykat.git") + url.set("https://github.com/serras/kopykat") + } + } + } +} + +plugins.withType().configureEach { + // only create a 'java' publication when the JavaPlugin is present + publishing { + publications { + register("maven") { + from(components["java"]) + } + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b52ac66..350fae3 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,6 +7,7 @@ assertj = "3.23.1" classgraph = "4.8.149" [libraries] +kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" } kotlin-stdlibCommon = { module = "org.jetbrains.kotlin:kotlin-stdlib-common" } kotlin-stdlibJDK8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } kotlinPoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" } @@ -17,6 +18,12 @@ kotlinCompileTestingKsp = { module = "com.github.tschuchortdev:kotlin-compile-te assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } classgraph = { module = "io.github.classgraph:classgraph", version.ref = "classgraph" } +### Plugins ### +# the *Maven coodinates* of Gradle plugins. Use in ./buildSrc/build.gradle.kts. + +gradlePlugin-kotlinJvm = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } + + [plugins] -kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -ksp = { id = "com.google.devtools.ksp", version.ref = "kspVersion" } \ No newline at end of file + +# import plugins using Maven coordinates (see above), not the Gradle plugin ID diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..a5396c1 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,5 @@ +# https://jitpack.io/docs/BUILDING/ + +# https://jitpack.io/docs/BUILDING/#java-version +jdk: + - openjdk11 diff --git a/ksp/build.gradle.kts b/ksp/build.gradle.kts index 5854e50..ead1c18 100644 --- a/ksp/build.gradle.kts +++ b/ksp/build.gradle.kts @@ -1,12 +1,6 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -@Suppress("DSL_SCOPE_VIOLATION") plugins { - alias(libs.plugins.kotlin.jvm) -} - -kotlin { - explicitApi() + buildsrc.conventions.`kotlin-jvm` + buildsrc.conventions.`maven-publish` } dependencies { @@ -18,11 +12,3 @@ dependencies { testRuntimeOnly(projects.ksp) } - -tasks.test { - useJUnitPlatform() -} - -tasks.withType { - kotlinOptions.jvmTarget = "1.8" -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 131e393..5589d70 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,10 @@ enableFeaturePreview("VERSION_CATALOGS") rootProject.name = "kopykat" -include(":ksp") -include(":utils:compilation") -include(":utils:kotlin-poet") +apply(from = "./buildSrc/repositories.settings.gradle.kts") + +include( + ":ksp", + ":utils:compilation", + ":utils:kotlin-poet", +) diff --git a/utils/compilation/build.gradle.kts b/utils/compilation/build.gradle.kts index 678ef80..bffdd1b 100644 --- a/utils/compilation/build.gradle.kts +++ b/utils/compilation/build.gradle.kts @@ -1,12 +1,8 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -@Suppress("DSL_SCOPE_VIOLATION") plugins { - alias(libs.plugins.kotlin.jvm) -} - -kotlin { - explicitApi() + buildsrc.conventions.`kotlin-jvm` + buildsrc.conventions.`maven-publish` } dependencies { @@ -25,7 +21,3 @@ dependencies { } implementation(libs.kotlinCompileTestingKsp) } - -tasks.withType { - kotlinOptions.jvmTarget = "1.8" -} diff --git a/utils/kotlin-poet/build.gradle.kts b/utils/kotlin-poet/build.gradle.kts index 233f677..90a4cea 100644 --- a/utils/kotlin-poet/build.gradle.kts +++ b/utils/kotlin-poet/build.gradle.kts @@ -1,12 +1,6 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - -@Suppress("DSL_SCOPE_VIOLATION") plugins { - alias(libs.plugins.kotlin.jvm) -} - -kotlin { - explicitApi() + buildsrc.conventions.`kotlin-jvm` + buildsrc.conventions.`maven-publish` } dependencies { @@ -14,7 +8,3 @@ dependencies { api(libs.kotlinPoet) api(libs.kotlinPoet.ksp) } - -tasks.withType { - kotlinOptions.jvmTarget = "1.8" -}