I’m trying to get kapt working on a multiplatform ...
# getting-started
d
I’m trying to get kapt working on a multiplatform gradle project, so far I have:
Copy code
configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
    jvm {
        val main by compilations.getting {
            kotlinOptions {
                freeCompilerArgs = listOf("-Xallow-result-return-type", "-Xinline-classes")
                jvmTarget = JavaVersion.VERSION_11.toString()
                javaParameters = true
            }
        }
    }
    sourceSets {
        val main by getting {
            dependencies {
...
                configurations["kapt"].dependencies.add(platform("io.micronaut:micronaut-bom:${properties["micronautVersion"]}"))
                configurations["kapt"].dependencies.add(project.dependencies.create("io.micronaut:micronaut-inject-java"))
            }
        }
    }
}
however when I run the
kaptKotlinJvm
task I’m getting:
Copy code
java.lang.IllegalArgumentException: The argument does not represent an annotation type: io.micronaut.context.annotation.Replaces
Any idea what I’m missing? What does this error mean, that the dependencies aren’t working or something else?
j
main source sets doesn't exist at least you are adding it manually
d
I had
jvmMain
before (based on some example of something on the internet) and it failed because it didn’t exist.
SourceSet with name 'jvmMain' not found
oh this is a folder thing, I have
src/main/kotlin
etc
previously this wasn’t a mpp project, I am converting it to one so that I can share some code
but step 1 is getting it working as a mpp
j
In kmp main source set doesn't exist, by default you have commonMain. For jvmMain you need to add jvm() which you are already adding, so it should bbe there
if you change that
val
to
val jvmMain
it doesnt work?
d
exacly
j
Copy code
sourceSets {
        val main by getting {
I mean this one
that is weird
d
yes, I get
SourceSet with name 'jvmMain' not found
j
then it looks like it is not detecting you are setting jvm() or another convention plugin is renaming it
maybe the
jvm {}
is not setting it, try to put jvm() too but it is weird
d
just tried that, no difference
using
main
works in that kapt starts, however then I get the
The argument does not represent an annotation type
error
should I change the directory structure to use
src/jvmMain
instead?
is there some magic going on?
j
yeah
I mean, the real folder should be named jvmMain instead of main
or indicate to KMP plugin to use main as jvmMain, but I wouldn't do that
d
oh, there is something else, this is a multi-module project and in the root build.gradle.kts I have to have a
kotlin { jvm {} }
block otherwise the build will fail telling me I need one. Could that be screwing things up?
j
I am not sure which will have preference, I think it should work when you rename the dir to jvmMain
probably they are "merged" because the root one doesnt mutate the state and the second one yes
d
ok, so I renamed it and used
jvm()
and still get
SourceSet with name 'jvmMain' not found
j
can you share both gradle files?
d
build.gradle.kts.kt
build.gradle.kts.txt
j
java library is not necessary
well it is in the root one
d
that gives
Copy code
Script compilation errors:

  Line 33:         test {
                   ^ Unresolved reference: test

  Line 34:             useJUnitPlatform()
                       ^ Unresolved reference: useJUnitPlatform

  Line 35:             testLogging {
                       ^ Unresolved reference: testLogging

  Line 36:                 exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
                           ^ Unresolved reference: exceptionFormat

  Line 37:                 showStackTraces = false
                           ^ Unresolved reference: showStackTraces
j
the root project has code?
d
and if I comment out those bits that fail I’m back to jvmMain sourceset not found
the root project does not have code
but it still demands the
jvm
block
j
If the root project has no code then you don't need kmp there
anyway it is weird it should be working 🤔
have you running it on terminal?
or via sync with the IDE?
d
terminal
just to be safe
j
yeah that is the correct way
d
I added
apply false
to the plugin declarations and now I can remove the
kotlin
config from the root file, thanks for that at least 🙂
but still in the same situation as before
Copy code
ls -l claimant-web-api/src
total 8
drwxr-xr-x 1 vagrant vagrant 128 Nov 27 01:51 jvmMain
drwxr-xr-x 1 vagrant vagrant  96 Nov 27 01:51 test
ok, I’ve removed all the other stuff that wasn’t to do with kotlin and also made sure all plugins are declared with
apply false
but still have the same sourceset not found issue 😭
j
Is it open source?
d
unfortunately not
ok using
val main
with a source directory named
jvmMain
has taken me a little further. I had to add
Copy code
configure<org.jetbrains.kotlin.gradle.plugin.KaptExtension> {
    correctErrorTypes = true
}
and now I have an error during kapt
Copy code
error: cannot find symbol
@Constraint()
which is a javax library. I have no idea why it can’t find that all of a sudden but it is not directly in my dependencies
basically I just seem to be getting lots of dependencies missing during kapt
ok working! so I had to use
val main
but the directory must be called
jvmMain
(or I think
commonMain
would also work. I also had to add
withJava()
into the kotlin config block (I assume because of the way kapt works, it generates java class files).
thnks so much @Javier for your help and anyone feel free to DM me if you are having similar issues
🙂 1