gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

Kapt multiplatform with jvm is throwing an error #1372

Closed steelxt closed 5 years ago

steelxt commented 5 years ago

I'm trying to build fullstack project with vert.x+ requery and kotlin js in the front, but I can't setup kapt due an error: kapt("io.requery:requery-processor:$requery_version") ^ Type mismatch: inferred type is String but Action< KaptExtension > was expected

Expected Behavior

kapt() should accept string type instead Action< KaptExtension >

Current Behavior

kapt due an error: kapt("io.requery:requery-processor:$requery_version") ^ Type mismatch: inferred type is String but Action was expected

Context

I want to use kapt multiplatform jvm and js

Steps to Reproduce (for bugs)

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

val requery_version = "1.5.1"
val rxjava2_version = "2.2.3"

plugins {
    kotlin("multiplatform") version "1.3.30"
    id("idea")
    kotlin("kapt") version "1.3.21"
}
group = "com.cps"
version = "1.0-SNAPSHOT"

repositories {
    maven("https://jcenter.bintray.com")
    mavenCentral()

}
kotlin{
    jvm() // Creates a JVM target with the default name 'jvm'
    js()  // JS target named 'js'
    sourceSets {

        jvm().compilations["main"].defaultSourceSet {

            dependencies {
                implementation(kotlin("stdlib-jdk8"))
                implementation( "io.vertx:vertx-web:${extra["vertxVersion"]}")
                implementation( "io.vertx:vertx-web-client:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-mysql-postgresql-client:${extra["vertxVersion"]}")
                implementation("net.postgis:postgis-jdbc:2.2.1")
                implementation("javax.cache:cache-api:1.1.0")
                implementation("org.ehcache:ehcache:3.5.2")
                implementation("io.reactivex.rxjava2:rxjava:$rxjava2_version")
                implementation("io.requery:requery:$requery_version")
                implementation("io.vertx:vertx-tcp-eventbus-bridge:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-lang-kotlin:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-auth-common:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-auth-oauth2:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-service-discovery:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-circuit-breaker:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-lang-kotlin-coroutines:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-config:${extra["vertxVersion"]}")
                implementation("io.vertx:vertx-hazelcast:${extra["vertxVersion"]}")

                implementation("org.postgresql:postgresql:9.4-1200-jdbc41")
                implementation("io.requery:requery-kotlin:$requery_version")
                //implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.0-alpha-2")
                implementation("org.slf4j:slf4j-simple:1.7.14")
               // kapt("io.requery:requery-processor:$requery_version")
            }
        }
    }

}
dependencies {
    kapt("io.requery:requery-processor:$requery_version")
}

Your Environment

eskatos commented 5 years ago

In that context, kapt resolves to the Project extension registered under the kapt name by the Kotlin Gradle Plugin. The extension to declare a dependency in the kapt Configuration isn't available in the kotlin.sourceSets.jvm().compilations["main"].defaultSourceSet.dependencies {} scope.

You can work around this in the following ways:

kotlin {
  sourceSets {
    jvm().compilations["main"].defaultSourceSet {
      dependencies {
        "kapt"(...)
        // or
        configurations.kapt(...)
      }
    }
  }
}

Please use the Gradle forums for support questions https://discuss.gradle.org/

martinbonnin commented 5 years ago

@eskatos any reason to not make this extension available ? I bumped into something similar in an android app using the multiplatform plugin.

andrewemery commented 5 years ago

@steelxtreme: The suggestion from @eskatos didn't work for me because kapt is undefined on configurations.

I wanted a annotation processing from a local dependency and the following worked:

dependencies {
    configurations.get("kapt").dependencies.add(project("dependency_path"))
}

I haven't tested, but the following may work in your instance for an external dependency:

dependencies {
    configurations.get("kapt").dependencies.add(DefaultExternalModuleDependency("io.requery", "requery-processor", "1.5.1"))
}
niqo01 commented 5 years ago

The suggestion from @eskatos didn't work for me either. I am now trying with :

configurations.get("kapt").dependencies.add(DefaultExternalModuleDependency("com.google.dagger", "dagger-compiler", "2.24"))

But I am getting the following error:

Could not determine the dependencies of task ':api:social-cats:kaptKotlinJvm'.
> Could not resolve all task dependencies for configuration ':api:social-cats:_classStructurekaptKotlinJvm'.
   > Could not resolve project :search:model.
     Required by:
         project :api:social-cats
      > Cannot choose between the following variants of project :search:model:
          - jsApiElements
          - jsCompile
          - jsCompileOnly
          - jsDefault
          - jsRuntime
          - jsRuntimeElements
          - jsTestCompile
          - jsTestRuntime
          - jvmApiElements
          - jvmCompile
          - jvmCompileOnly
          - jvmDefault
          - jvmRuntime
          - jvmRuntimeElements
          - jvmTestCompile
          - jvmTestRuntime
          - metadataApiElements
          - metadataCompile
          - metadataCompileOnly
          - metadataDefault
andrewemery commented 5 years ago

@niqo01 This is a separate issue.

If your Gradle plugin cannot determine the correct configuration for the dependency automatically then you need to specify the configuration manually [1]:

implementation project(path: ':search:model', configuration: 'jvmDefault')

[1] Note: The above is in Groovy. You'll need to translate it to Kotlin for your project.

21region commented 4 years ago

@steelxtreme: The suggestion from @eskatos didn't work for me because kapt is undefined on configurations.

I wanted a annotation processing from a local dependency and the following worked:

dependencies {
    configurations.get("kapt").dependencies.add(project("dependency_path"))
}

I haven't tested, but the following may work in your instance for an external dependency:

dependencies {
    configurations.get("kapt").dependencies.add(DefaultExternalModuleDependency("io.requery", "requery-processor", "1.5.1"))
}

That was very very hard to find. I struggled for a weak before I stumbled upon this. I have even sacrificed 90% of my reputation on stackoverflow to get this answer... https://stackoverflow.com/questions/59321848/using-kapt-with-multiplatform-subproject