Skip to content

Commit

Permalink
Apply KMP plugin only to the kotlinpoet module
Browse files Browse the repository at this point in the history
  • Loading branch information
takahirom committed Aug 5, 2023
1 parent 84560cb commit b85cfb6
Show file tree
Hide file tree
Showing 125 changed files with 98 additions and 115 deletions.
39 changes: 24 additions & 15 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.ksp) apply false
// alias(libs.plugins.dokka) apply false
alias(libs.plugins.spotless) apply false
Expand All @@ -43,11 +44,6 @@ allprojects {
}

subprojects {
apply(plugin = "org.jetbrains.kotlin.multiplatform")
configure<KotlinMultiplatformExtension> {
jvm {}
}

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
Expand All @@ -62,8 +58,15 @@ subprojects {
if ("test" !in name && buildFile.exists()) {
// apply(plugin = "org.jetbrains.dokka")
apply(plugin = "com.vanniktech.maven.publish")
configure<KotlinProjectExtension> {
explicitApi()
pluginManager.withPlugin("org.jetbrains.kotlin.multiplatform") {
configure<KotlinMultiplatformExtension> {
explicitApi()
}
}
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure<KotlinProjectExtension> {
explicitApi()
}
}
// Unable to run dokka with single target multiplatform project and
// kotlin 1.9.0
Expand All @@ -78,7 +81,6 @@ subprojects {
// }
// }
}

apply(plugin = "com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
Expand Down Expand Up @@ -106,7 +108,7 @@ subprojects {
| * See the License for the specific language governing permissions and
| * limitations under the License.
| */
""".trimMargin()
""".trimMargin(),
)
}
}
Expand All @@ -120,16 +122,23 @@ subprojects {
for (majorVersion in versionsToTest) {
val jdkTest = tasks.register<Test>("testJdk$majorVersion") {
val javaToolchains = project.extensions.getByType(JavaToolchainService::class)
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(majorVersion))
vendor.set(JvmVendorSpec.AZUL)
})
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(majorVersion))
vendor.set(JvmVendorSpec.AZUL)
},
)

description = "Runs the test suite on JDK $majorVersion"
group = LifecycleBasePlugin.VERIFICATION_GROUP

// Copy inputs from normal Test task.
val testTask = tasks.getByName<Test>("jvmTest")
val testTask =
if (pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
tasks.getByName<Test>("jvmTest")
} else {
tasks.getByName<Test>("test")
}
classpath = testTask.classpath
testClassesDirs = testTask.testClassesDirs

Expand All @@ -148,6 +157,6 @@ apiValidation {
nonPublicMarkers += "com.squareup.kotlinpoet.ExperimentalKotlinPoetApi"
ignoredProjects += listOf(
"interop", // Empty middle package
"test-processor" // Test only
"test-processor", // Test only
)
}
27 changes: 10 additions & 17 deletions interop/javapoet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
kotlin("jvm")
}

project.tasks.withType(org.gradle.jvm.tasks.Jar::class.java) {
tasks.jar {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet")
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet.javapoet")
}
}

kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
api(projects.kotlinpoet)
api(libs.javapoet)
}
}
val jvmTest by getting {
dependencies {
implementation(libs.kotlin.junit)
implementation(libs.truth)
}
}
}
dependencies {
api(projects.kotlinpoet)
api(libs.javapoet)
testImplementation(libs.kotlin.junit)
testImplementation(libs.truth)
}
42 changes: 18 additions & 24 deletions interop/kotlinx-metadata/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
kotlin("jvm")
}

project.tasks.withType(org.gradle.jvm.tasks.Jar::class.java) {
tasks.jar {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet")
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet.metadata")
}
}

project.tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileTestKotlinJvm") {
tasks.compileTestKotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-Xjvm-default=all",
Expand All @@ -30,25 +33,16 @@ project.tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileTes
}
}

kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
implementation(libs.autoCommon)
implementation(libs.guava)
api(libs.kotlin.metadata)
api(projects.kotlinpoet)
}
}
val jvmTest by getting {
dependencies {
implementation(libs.kotlin.junit)
implementation(libs.truth)
implementation(libs.compileTesting)
implementation(libs.kotlinCompileTesting)
implementation(libs.kotlin.annotationProcessingEmbeddable)
implementation(libs.kotlin.compilerEmbeddable)
}
}
}
dependencies {
implementation(libs.autoCommon)
implementation(libs.guava)
api(libs.kotlin.metadata)
api(projects.kotlinpoet)

testImplementation(libs.kotlin.junit)
testImplementation(libs.truth)
testImplementation(libs.compileTesting)
testImplementation(libs.kotlinCompileTesting)
testImplementation(libs.kotlin.annotationProcessingEmbeddable)
testImplementation(libs.kotlin.compilerEmbeddable)
}
28 changes: 10 additions & 18 deletions interop/ksp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,19 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins {
kotlin("jvm")
}

project.tasks.withType(org.gradle.jvm.tasks.Jar::class.java) {
tasks.jar {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet")
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet.ksp")
}
}


kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
api(projects.kotlinpoet)
compileOnly(libs.ksp.api)
}
}
val jvmTest by getting {
dependencies {
implementation(libs.kotlin.junit)
implementation(libs.truth)
}
}
}
dependencies {
api(projects.kotlinpoet)
compileOnly(libs.ksp.api)
testImplementation(libs.kotlin.junit)
testImplementation(libs.truth)
}
45 changes: 16 additions & 29 deletions interop/ksp/test-processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,28 @@
*/
plugins {
id("com.google.devtools.ksp")
kotlin("jvm")
}

project.tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileTestKotlinJvm") {
tasks.compileTestKotlin {
compilerOptions {
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
}

kotlin {
sourceSets {
val jvmMain by getting {
dependencies {
implementation(projects.kotlinpoet)
implementation(projects.interop.ksp)
implementation(libs.autoService)
compileOnly(libs.ksp.api)
}
}
val jvmTest by getting {
dependencies {

// Always force the latest version of the KSP/kotlin impl in tests to match what we're building against
implementation(libs.ksp.api)
implementation(libs.kotlin.compilerEmbeddable)
implementation(libs.kotlin.annotationProcessingEmbeddable)
implementation(libs.ksp)
implementation(libs.kotlinCompileTesting)
implementation(libs.kotlinCompileTesting.ksp)
implementation(libs.kotlin.junit)
implementation(libs.truth)
}
}
}
}

dependencies {
add("kspJvm", libs.autoService.ksp)
implementation(projects.kotlinpoet)
implementation(projects.interop.ksp)
implementation(libs.autoService)
compileOnly(libs.ksp.api)
ksp(libs.autoService.ksp)
// Always force the latest version of the KSP/kotlin impl in tests to match what we're building against
testImplementation(libs.ksp.api)
testImplementation(libs.kotlin.compilerEmbeddable)
testImplementation(libs.kotlin.annotationProcessingEmbeddable)
testImplementation(libs.ksp)
testImplementation(libs.kotlinCompileTesting)
testImplementation(libs.kotlinCompileTesting.ksp)
testImplementation(libs.kotlin.junit)
testImplementation(libs.truth)
}
32 changes: 20 additions & 12 deletions kotlinpoet/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
project.tasks.withType(org.gradle.jvm.tasks.Jar::class.java) {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet")
}
}

project.tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileTestKotlinJvm") {
compilerOptions {
freeCompilerArgs.add("-opt-in=com.squareup.kotlinpoet.DelicateKotlinPoetApi")
}
plugins {
kotlin("multiplatform")
}

spotless {
Expand All @@ -37,14 +29,17 @@ spotless {
)
}
}

kotlin {
jvm()

sourceSets {
val jvmMain by getting {
val commonMain by getting {
dependencies {
implementation(libs.kotlin.reflect)
}
}
val jvmTest by getting {
val commonTest by getting {
dependencies {
implementation(libs.kotlin.junit)
implementation(libs.truth)
Expand All @@ -59,3 +54,16 @@ kotlin {
}
}
}

project.tasks.withType(org.gradle.jvm.tasks.Jar::class.java) {
manifest {
attributes("Automatic-Module-Name" to "com.squareup.kotlinpoet")
}
}

project.tasks.named<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>("compileTestKotlinJvm") {
compilerOptions {
freeCompilerArgs.add("-opt-in=com.squareup.kotlinpoet.DelicateKotlinPoetApi")
}
}

0 comments on commit b85cfb6

Please sign in to comment.