JLink: Cannot find module-info.java in project - kotlin

I was trying to create runtime for my project, but suddenly I got an error and I couldn't find any info about it. The project is setted up as kotlin+gradle and nothing more.
I use badass-jlink-plugin and log4j2. The error:
Execution failed for task ':prepareModulesDir'.
> Error while evaluating property 'moduleName' of task ':prepareModulesDir'
> Failed to query the value of extension 'jlink' property 'moduleName'.
> Cannot find module-info.java in [ProjectFolder\src\main\java]
My build.gradle (not full):
buildscript {
...
}
plugins {
id 'application'
id 'org.jetbrains.kotlin.jvm' version '1.8.0'
id 'org.beryx.jlink' version '2.26.0'
// id 'org.jetbrains.kotlin.multiplatform' version '1.8.0'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.0'
}
apply plugin: 'kotlin'
apply plugin: 'kotlinx-serialization'
group = 'com.adisalagic.codenames'
version = '1.0-SNAPSHOT'
mainClassName = 'com.adisalagic.codenames.Main'
repositories {
mavenCentral()
}
dependencies {
// implementation "org.jetbrains.kotlin:kotlin-serialization:1.8.0"
testImplementation 'org.jetbrains.kotlin:kotlin-test'
// implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0-RC")
implementation 'org.apache.logging.log4j:log4j-api:2.19.0'
implementation 'org.apache.logging.log4j:log4j-core:2.19.0'
implementation 'com.google.code.gson:gson:2.10.1'
}
test {
useJUnitPlatform()
}
jlink {
options = ['--strip-debug', '--compress', '2', '--no-header-files', '--no-man-pages']
forceMerge 'log4j-api'
}
jar {
manifest {
attributes "Main-Class": "$mainClassName"
}
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
tasks.withType(Jar).configureEach {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
manifest {
attributes["Main-Class"] = "$mainClassName"
}
}
kotlin {
// jvmToolchain(8)
}
Should I create module-info myself?
I've discovered that it only happened when I use forceMerge. But everywhere it is suggested to be used.

Related

How to package a kotlin project with JavaFX in it?

my team got a kotlin project with JavaFX as frontEnd. The problem we have is using jlink to produce a package.
Here is my build.gradle for the project.
Could anyone help me take a look at how to change this?
ps: I have already tried with
command-line javac
jlink from the intellij
create a new Main method and use the shadow plugin for jlink.
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.4'
}
}
plugins {
id "java"
id "application"
id "org.jetbrains.kotlin.jvm" version "1.6.10"
id "org.openjfx.javafxplugin" version "0.0.12"
id "org.beryx.jlink" version "2.25.0"
// Json
id "org.jetbrains.kotlin.plugin.serialization" version "1.6.10"
}
group "com.yyil"
version "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
ext {
junitVersion = "5.8.1"
}
sourceCompatibility = "16"
targetCompatibility = "16"
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
application {
mainClass = 'com.yyil.noteapp.NewMain'
}
[compileKotlin, compileTestKotlin].forEach {
it.kotlinOptions {
jvmTarget = "16"
}
}
javafx {
version = "17.0.2"
modules = ["javafx.controls", "javafx.fxml", "javafx.web", "javafx.swing", "javafx.graphics", "javafx.base"]
}
dependencies {
implementation("org.controlsfx:controlsfx:11.1.0")
implementation("net.synedra:validatorfx:0.1.13") {
exclude(group: "org.openjfx")
}
implementation("org.kordamp.ikonli:ikonli-javafx:12.2.0")
implementation("eu.hansolo:tilesfx:11.48") {
exclude(group: "org.openjfx")
}
// JSON
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2")
// testing JavaFX
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitVersion}")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:${junitVersion}")
testImplementation("org.testfx:testfx-core:4.0.16-alpha")
testImplementation("org.testfx:testfx-junit5:4.0.16-alpha")
testImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
// database (sqlite)
implementation "org.xerial:sqlite-jdbc:3.30.1"
// svg support
implementation("org.apache.xmlgraphics:batik-transcoder:1.14")
}
test {
useJUnitPlatform()
}
When I try to build it, I got errors like:

Export Kotlin code to jar is recognized as Java code on the consumer project

I'm working on a multi-module repository. One module exports Kotlin library, and the other one consumes the artifact and uses it.
I've noticed that once I'm trying to use named parameters inside the consumer it tells me that I cannot do this in a non-kotlin code (e.g. from Java). When I've tried to decompile the code of the library I've seen that the code I see there is indeed Java code (however this might be related to the fact that IntelliJ decompile everything into Java?)
The entire code can be found in this following link where demo-app is the consumer and rabbit-hole is the producer
Just for complicity, I'll put the build gradle file of both here as well:
Library:
plugins {
id "java"
id "org.jetbrains.kotlin.jvm"
id "org.jetbrains.kotlin.plugin.allopen"
id "jacoco"
id "maven-publish"
id "org.springframework.boot"
id "io.spring.dependency-management"
id "com.diffplug.spotless"
}
jar {
enabled = true
}
bootJar {
enabled = false
}
dependencies {
implementation group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8"
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-amqp'
// Tests
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation group: 'io.mockk', name: 'mockk', version: '1.12.1'
}
build {
finalizedBy spotlessApply
}
test {
useJUnitPlatform()
finalizedBy spotlessApply
finalizedBy jacocoTestReport
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.yonatankarp'
artifactId = project.name
version = project.version
from components.java
versionMapping {
usage('java-runtime') {
fromResolutionResult()
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/yonatankarp/rabbit-hole")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
}
}
}
}
allOpen {
annotation("org.springframework.context.annotation.Configuration")
}
Consumer:
plugins {
id "java"
id "org.jetbrains.kotlin.jvm"
id "org.jetbrains.kotlin.plugin.allopen"
id "jacoco"
id "org.springframework.boot"
id "io.spring.dependency-management"
id "com.diffplug.spotless"
}
group = 'com.yonatankarp'
version "${version}"
sourceCompatibility = '11'
jar {
enabled = false
}
bootJar {
enabled = true
}
repositories {
mavenLocal()
mavenCentral()
maven {
name = "Rabbit Hole"
url = uri("https://maven.pkg.github.com/yonatankarp/rabbit-hole")
credentials {
username = project.findProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
password = project.findProperty("gpr.key") ?: System.getenv('GITHUB_TOKEN')
}
}
}
dependencies {
implementation group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8"
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-amqp'
implementation "com.yonatankarp:rabbit-hole:+"
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
}
build {
finalizedBy spotlessApply
}
test {
useJUnitPlatform()
finalizedBy spotlessApply
finalizedBy jacocoTestReport
}
allOpen {
annotation("org.springframework.context.annotation.Configuration")
}
EDIT
For clarity: Both the library and the consumer of it are written in Kotlin

Why do I get no main manifest attribute, in rome-utils-1.15.0.jar?

I am trying to use the rome rss library. However, when I go to execute my jar I get the error.
I am assuming it has something to do with my build.gradle.kts file. I have copied it here
buildscript {
repositories {
maven("https://plugins.gradle.org/m2/")
maven(url = "https://www.jitpack.io") {
name = "jitpack"
}
flatDir {
dirs("libs")
}
}
dependencies {
}
}
plugins {
application
kotlin("jvm") version "1.4.0"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
application {
mainClassName = "io.ktor.server.netty.EngineMain"
}
repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url = uri("https://kotlin.bintray.com/ktor") }
maven(url = "https://www.jitpack.io") {
name = "jitpack"
}
}
tasks {
withType<KotlinCompile> {
kotlinOptions.jvmTarget = "11"
}
named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar") {
archiveBaseName.set("freedom")
archiveClassifier.set("")
archiveVersion.set("1.1.0")
manifest {
attributes(mapOf("Main-Class" to application.mainClassName))
}
}
}
dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version")
implementation("io.ktor:ktor-server-netty:$ktor_version")
implementation("com.rometools:rome:1.15.0")
implementation("ch.qos.logback:logback-classic:$logback_version")
implementation("io.ktor:ktor-client-core:$ktor_version")
implementation("io.ktor:ktor-client-core-jvm:$ktor_version")
implementation("io.ktor:ktor-gson:$ktor_version")
implementation("io.ktor:ktor-client-apache:$ktor_version")
implementation("io.ktor:ktor-html-builder:$ktor_version")
implementation("com.github.chimbori:crux:2.2.0")
implementation("org.jsoup:jsoup:1.13.1")
implementation("io.lettuce:lettuce-core:6.0.1.RELEASE")
implementation("org.jetbrains.exposed", "exposed-core", "0.28.1")
implementation("org.jetbrains.exposed", "exposed-dao", "0.28.1")
implementation("org.jetbrains.exposed", "exposed-jdbc", "0.28.1")
implementation("com.google.firebase:firebase-admin:7.0.1")
implementation("org.postgresql", "postgresql", "42.2.18")
implementation("com.zaxxer:HikariCP:3.4.5")
implementation("com.github.kittinunf.fuel:fuel:2.3.0")
implementation("com.github.kittinunf.fuel:fuel-gson:2.3.0")
testImplementation("io.ktor:ktor-server-tests:$ktor_version")
}
kotlin.sourceSets["main"].kotlin.srcDirs("src")
kotlin.sourceSets["test"].kotlin.srcDirs("test")
sourceSets["main"].resources.srcDirs("resources")
sourceSets["test"].resources.srcDirs("testresources")
My app builds fine without this library. However, I need to use this particular library. I have tried steps in similar questions but they did not work. When trying to execute my program I get no main manifest attribute, in rome-utils-1.15.0.jar
The problem lies with shadowJar improperly building the Rome jar. This is something that must be taken up on the shadowJar's github.
I came across the same issue and I'm sure that problem is not in the build.gradle file.
I believe you want mainClass not mainClassName per Gradle user guide
So try
application {
mainClass = "io.ktor.server.netty.EngineMain"
}

How Do I Resolve This Type Mismatch?

So I was working on converting my build.gradle (Which uses Groovy) to a build.gradle.kts (Which uses Kotlin) and this is what I got so far:
Groovy Original:
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.3.72'
id 'com.github.johnrengelman.shadow' version '5.2.0'
}
group 'com.smushytaco'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
maven {
url 'https://papermc.io/repo/repository/maven-public/'
}
}
dependencies {
implementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.3.72'
//https://papermc.io/javadocs/paper/1.16/overview-summary.html
compileOnly group: 'com.destroystokyo.paper', name: 'paper-api', version: '1.16.1-R0.1-SNAPSHOT'
}
shadowJar {
getArchiveClassifier().set('')
project.configurations.implementation.canBeResolved = true
configurations = [project.configurations.implementation]
relocate 'kotlin', 'com.smushytaco.src.main.kotlin.com.smushytaco.plugin'
}
build.dependsOn shadowJar
Kotlin Conversion:
plugins {
java
kotlin("jvm") version("1.3.72")
id("com.github.johnrengelman.shadow") version("5.2.0")
}
group = "com.smushytaco"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
maven("https://papermc.io/repo/repository/maven-public/")
}
dependencies {
implementation("org.jetbrains.kotlin", "kotlin-stdlib", "1.3.72")
//https://papermc.io/javadocs/paper/1.16/overview-summary.html
compileOnly("com.destroystokyo.paper", "paper-api", "1.16.1-R0.1-SNAPSHOT")
}
tasks {
shadowJar {
archiveClassifier.set("")
project.configurations.implementation.get().isCanBeResolved = true
// Type Mismatch:
// Required: (Mutable)List<Configuration!>!
//Found: Array<NamedDomainObjectProvider<Configuration>>
configurations = [project.configurations.implementation]
relocate("kotlin", "com.smushytaco.src.main.kotlin.com.smushytaco.plugin")
}
build {
dependsOn(shadowJar)
}
}
I commented the error I'm getting with the Kotlin rewrite, why does it work with the original Groovy one and not with this one? How do I fix this error?
Use this:
configurations = listOf(project.configurations.implementation.get())

Cannot update kotlin to v1.3.50 for multiplatform project

I'm using kotlin 1.3.41 for my multiplatform project (included ios, jvm, js) and everything is ok. Now I'm trying to update to the latest version 1.3.50 but get this error:
Could not determine the dependencies of task ':kotlinNpmInstall'.
> org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager$ResolutionState$Installed cannot be cast to org.jetbrains.kotlin.gradle.targets.js.npm.KotlinNpmResolutionManager$ResolutionState$Configuring
I have tried to search everywhere (github, kotlin issue tracker) but got nothing. Does anyone know what causes this error? Thanks.
Part of my configuration:
Root project configuration
buildscript {
apply from: "buildsystem/dependencies.gradle"
repositories {
google()
jcenter()
mavenCentral()
maven { url "https://dl.bintray.com/kotlin/kotlinx/" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath deps.gradlePlugins.android
classpath deps.gradlePlugins.androidNavigation
classpath deps.gradlePlugins.node
classpath deps.gradlePlugins.kotlin
classpath deps.gradlePlugins.kotlinSerialization
classpath deps.gradlePlugins.kotlinAtomicfun
classpath deps.gradlePlugins.dokka
}
}
Multiplatform module configuration
apply plugin: 'org.jetbrains.kotlin.multiplatform'
apply plugin: 'kotlinx-serialization'
kotlin {
targets {
jvm("jvm")
js("js") {
nodejs {}
}
iosArm64("ios64")
iosX64("iosSim")
configure([ios64, iosSim]) {
binaries.framework {
baseName = "LIB"
}
}
}
sourceSets {
def commonDependencies = rootProject.ext.deps.common
commonMain {
dependencies {
implementation commonDependencies.kotlin
implementation commonDependencies.kotlinCoroutines
}
}
commonTest {
dependencies {
implementation commonDependencies.kotlinTest
implementation commonDependencies.kotlinTestAnnotations
implementation commonDependencies.mockk
}
}
def jvmDependencies = rootProject.ext.deps.jvm
jvmMain {
dependencies {
implementation jvmDependencies.kotlin
implementation jvmDependencies.kotlinCoroutines
}
}
jvmTest {
dependencies {
implementation jvmDependencies.kotlinTest
implementation jvmDependencies.kotlinTestJunit
implementation jvmDependencies.kotlinCoroutinesTest
implementation jvmDependencies.mockk
}
}
def jsDependencies = rootProject.ext.deps.js
jsMain {
dependencies {
implementation jsDependencies.kotlin
implementation jsDependencies.kotlinCoroutines
// npm
implementation npm("uuid", "^3.3.2")
}
}
jsTest {
dependsOn jsMain
dependsOn commonMain
dependencies {
implementation jsDependencies.kotlinTest
}
}
def iosDependencies = rootProject.ext.deps.ios
iosMain {
dependencies {
implementation iosDependencies.kotlinCoroutines
}
}
ios64Main {
dependsOn iosMain
}
iosSimMain {
dependsOn iosMain
}
}
}
// other configuration
I can confirm that the issue is in Android Studio.
When I run the official KotlinJS react app tutorial on IntelliJ, the app works. But on AS, I get the above error when executing any Gradle task dependent on npm.
Until the issue is resolved, I recommend using the Community version of IntelliJ. You can download it here