Skip to content

Commit

Permalink
Migrate Kotlin/Java configurations to build-logic convention plugins (
Browse files Browse the repository at this point in the history
#110)

* Migrate Kotlin/Java configurations to `build-logic` convention plugins

* Update build-logic.api
  • Loading branch information
arunkumar9t2 committed Jul 20, 2022
1 parent 22b94b8 commit a51dc11
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 29 deletions.
12 changes: 12 additions & 0 deletions build-logic/api/build-logic.api
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ public class gradle/ConfigurablePlugin : org/gradle/api/Plugin {
public fun apply (Lorg/gradle/api/Project;)V
}

public final class javaplugin/JavaCommonKt {
public static final fun javaCommon (Lorg/gradle/api/Project;)V
}

public final class javaplugin/JavaLibrary : gradle/ConfigurablePlugin {
public fun <init> ()V
}

public final class kt/KotlinLibrary : gradle/ConfigurablePlugin {
public fun <init> ()V
}

public final class publish/PublishingCommon : gradle/ConfigurablePlugin {
public fun <init> ()V
}
Expand Down
8 changes: 8 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
}
gradlePlugin {
plugins {
create("javaLibrary") {
id = "java-library-plugin"
implementationClass = "javaplugin.JavaLibrary"
}
create("kotlinLibrary") {
id = "kotlin-library-plugin"
implementationClass = "kt.KotlinLibrary"
}
create("androidLibrary") {
id = "android-library-plugin"
implementationClass = "android.AndroidLibrary"
Expand Down
4 changes: 2 additions & 2 deletions build-logic/src/main/kotlin/gradle/Extension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ import org.gradle.kotlin.dsl.findByType
/**
* Configures a gradle extension if it exists and does nothing otherwise
*/
internal inline fun <reified T : Any> Project.configureIfExist(builder: (T) -> Unit) {
extensions.findByType<T>()?.let(builder)
internal inline fun <reified T : Any> Project.configureIfExist(builder: T.() -> Unit) {
extensions.findByType<T>()?.apply(builder)
}
29 changes: 29 additions & 0 deletions build-logic/src/main/kotlin/javaplugin/JavaCommon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2022 Arunkumar
*
* 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.
*/

package javaplugin

import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.kotlin.dsl.configure

public fun Project.javaCommon() {
configure<JavaPluginExtension> {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
26 changes: 26 additions & 0 deletions build-logic/src/main/kotlin/javaplugin/JavaLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2022 Arunkumar
*
* 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.
*/

package javaplugin

import gradle.ConfigurablePlugin
import org.gradle.api.plugins.JavaPlugin
import org.gradle.kotlin.dsl.apply

public class JavaLibrary : ConfigurablePlugin({
apply<JavaPlugin>()
javaCommon()
})
28 changes: 28 additions & 0 deletions build-logic/src/main/kotlin/kt/KotlinLibrary.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2022 Arunkumar
*
* 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.
*/

package kt

import gradle.ConfigurablePlugin
import javaplugin.JavaLibrary
import org.gradle.kotlin.dsl.apply

public class KotlinLibrary : ConfigurablePlugin({
apply<JavaLibrary>()
apply(plugin = "org.jetbrains.kotlin.jvm")
kotlinCommon()
// TODD(arun) Make kapt configurable from extension
})
3 changes: 1 addition & 2 deletions dot-dsl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "publish"
}
description = "Build dot files easily with Kotlin"
Expand Down
2 changes: 1 addition & 1 deletion samples/java-library-kts-script/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import dev.arunkumar.scabbard.gradle.ScabbardPluginExtension

plugins {
`java-library`
id("kotlin-library-plugin")
application
}
apply(plugin = "scabbard.gradle")
Expand Down
16 changes: 2 additions & 14 deletions scabbard-idea-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,18 @@
* limitations under the License.
*/


import org.jetbrains.intellij.tasks.RunPluginVerifierTask.FailureLevel
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id "org.jetbrains.intellij" version "1.0"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
}

repositories {
mavenCentral()
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
toolchain {
// languageVersion = JavaLanguageVersion.of(11)
}
}

tasks.withType(KotlinCompile).configureEach {
kotlinOptions.jvmTarget = "1.8"
}

dependencies {
testImplementation deps.junit
testImplementation deps.truth
Expand Down
3 changes: 1 addition & 2 deletions scabbard-processor-tests/common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "kotlin-kapt"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "kotlin-kapt"
}

Expand Down
3 changes: 1 addition & 2 deletions scabbard-processor-tests/qualified-names-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "kotlin-kapt"
}

Expand Down
3 changes: 1 addition & 2 deletions scabbard-processor-tests/svg-format-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "kotlin-kapt"
}

Expand Down
3 changes: 1 addition & 2 deletions scabbard-processor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

plugins {
id "java-library"
id "org.jetbrains.kotlin.jvm"
id "kotlin-library-plugin"
id "kotlin-kapt"
id "publish"
}
Expand Down

0 comments on commit a51dc11

Please sign in to comment.