In my Kotlin MP project, the jvm target generates ...
# multiplatform
s
In my Kotlin MP project, the jvm target generates an output name such as this: MyProject*-jvm*.jar. How would I configure it to not have the -jvm suffix?
k
looks like the target object has a
targetName
property - that may be the ticket
oh - internal set
maybe not
seems like this should be easy, but I don't see a way to do it
u
One way to do it is to name the target, so for example in
build.gradle.kts
when defining targets yo do something like this:
Copy code
kotlin {
    jvm("yourtargetname")
}
In
build.gradle
it would be something like this:
Copy code
kotlin {
    targets {
        fromPreset(presets.jvm, 'yourtargetname') {
        ...
        }
    }
}
I found this out because I did that by mistake in my library, and it actually brought some confusion 🙂
d
Copy code
val jvmJar by tasks.getting(Jar::class) {
    archiveName.set("...")
    archiveClassifier.set("...")
}
s
@Ugi Sure, but naming your target like that have an impact on your folder structure, hasn't it? Although it's not a big deal, I'll try to avoid it if I can.
@Dico Where exactly (in build.gradle) should I put this code snippet?
d
My code snippet is for kotlin gradle dsl, you'll need to translate it to groovy. Put it at the bottom of the file.
u
Yes, you are right, it does expect the source sets to be named
yourtargetnameMain
and
yourtargetnameTest
d
I recommend reading the archive* properties' documentation from the Jar task type
s
I have to go, but will take a look at it tomorrow morning.
So I'm trying something like this:
Copy code
Jar jvmJar = tasks.getByName('jvmJar') {
    from sourceSets
    archiveFileName = "${archiveBaseName}.jar"
}
But when I build my project it doesn't seem to like the ${variable} syntax. Can I use it on such an assignment?
d
Why are you doing
from sourceSets
? As for your question I suggest looking up groovy string interpolation.
s
Somehow I thought a
from
clause was necessary. I removed it. Will look into groovy string interpolation now...
In fact, when I write
archiveFileName = "${archiveBaseName}.jar"
, compiler doesn't complain but result file is ${archiveBaseName}.jar. ☹️
Nevermind, I had a typo in my variable name. Should have been archive`s`BaseName.