Skip to content

Commit

Permalink
migrate Gradle config to use to buildSrc convention plugins (#39)
Browse files Browse the repository at this point in the history
* migrate Gradle config to use to buildSrc convention plugins

* jdk11
  • Loading branch information
aSemy authored Sep 24, 2022
1 parent 8ad7d4c commit 16799bf
Show file tree
Hide file tree
Showing 13 changed files with 191 additions and 90 deletions.
51 changes: 4 additions & 47 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<PublishingExtension> {
publications {
create<MavenPublication>("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://[email protected]/serras/kopykat.git")
url.set("https://github.com/serras/kopykat")
}
}
}
}
}
}
group = "com.github.serras.kopykat"
version = "0.1"
41 changes: 41 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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<KotlinCompile>().configureEach {
kotlinOptions {
jvmTarget = gradleJvmTarget
apiVersion = gradleKotlinTarget
languageVersion = gradleKotlinTarget
}
}


kotlin {
jvmToolchain {
(this as JavaToolchainSpec).languageVersion.set(JavaLanguageVersion.of(gradleJvmTarget))
}
}


kotlinDslPluginOptions {
jvmTarget.set(gradleJvmTarget)
}
24 changes: 24 additions & 0 deletions buildSrc/repositories.settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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")
}
12 changes: 12 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -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"))
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package buildsrc.conventions

plugins {
`maven-publish`
}

publishing {
// configure all publications to have the same POM
publications.withType<MavenPublication>().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://[email protected]/serras/kopykat.git")
url.set("https://github.com/serras/kopykat")
}
}
}
}

plugins.withType<JavaPlugin>().configureEach {
// only create a 'java' publication when the JavaPlugin is present
publishing {
publications {
register<MavenPublication>("maven") {
from(components["java"])
}
}
}
}
11 changes: 9 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand All @@ -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" }

# import plugins using Maven coordinates (see above), not the Gradle plugin ID
5 changes: 5 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# https://jitpack.io/docs/BUILDING/

# https://jitpack.io/docs/BUILDING/#java-version
jdk:
- openjdk11
18 changes: 2 additions & 16 deletions ksp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,11 +12,3 @@ dependencies {

testRuntimeOnly(projects.ksp)
}

tasks.test {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
10 changes: 7 additions & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
12 changes: 2 additions & 10 deletions utils/compilation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -25,7 +21,3 @@ dependencies {
}
implementation(libs.kotlinCompileTestingKsp)
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
14 changes: 2 additions & 12 deletions utils/kotlin-poet/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
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 {
implementation(libs.ksp)
api(libs.kotlinPoet)
api(libs.kotlinPoet.ksp)
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

0 comments on commit 16799bf

Please sign in to comment.