javax.json module not found building JavaFX application with Gradle - gradle

I am trying to run a modular JavaFX application, with few other modular and non modular dependencies, using Gradle, but I am stuck with dependencies resolution.
The project is in Eclipse, using OpenJDK 14-. I have been able ot run, build and package the same application as non-modular using the org.beryx.runtime pluging https://badass-runtime-plugin.beryx.org/releases/latest/ , but I would like to go a step forward and make it modular, so now I am using the Badass JLink Plugin https://badass-jlink-plugin.beryx.org
To go step by step, I downloaded and tested this example: https://github.com/beryx-gist/badass-jlink-example-log4j2-javafx which is similar to my project and I succesfully ran it. Anyway, Eclipse marks lots of errors due to unresolved imports, which I would like to understand how to remove, but indeed the project compiles and runs.
The next step have been to modify this working example by adding the dependencies I need for my real project, which are mainly javax.json and jOpenDocument. The latter cannot be found as a module.
Here is the modified module-info.java
module hellofx {
requires javafx.controls;
requires org.apache.logging.log4j;
requires javax.json;
requires org.glassfish;
exports org.openjfx;
}
and the build.gradle
plugins {
id 'application'
id 'org.javamodularity.moduleplugin' version '1.8.9'
id 'org.openjfx.javafxplugin' version '0.0.10'
id "org.beryx.jlink" version "2.24.1"
}
repositories {
mavenCentral()
}
sourceCompatibility = "11"
targetCompatibility = "11"
dependencies {
implementation 'org.apache.logging.log4j:log4j-core:2.11.1'
implementation 'javax.json:javax.json-api:1.1.4'
implementation 'org.glassfish:javax.json:1.1.4'
implementation 'org.jopendocument:jOpenDocument:1.3'
}
javafx {
version = 16
modules = ['javafx.controls']
}
application {
mainClass = "org.openjfx.HelloFX"
mainModule = "hellofx"
}
The compileJava task fails with the following errors:
C:\Users\xxx\badass-jlink-example-log4j2-javafx-master\src\main\java\module-info.java:5: error: module not found: javax.json
requires javax.json;
^
C:\Users\xxx\badass-jlink-example-log4j2-javafx-master\src\main\java\module-info.java:6: error: module not found: org.glassfish
requires org.glassfish;
does anybody have a hint to start solving this issue?

The problem seemed to be related to the module-info.class file included in the older javax.json imported as org.glassfish:javax.json:1.1.4. The library has been relocated to jakarta and the new one org.glassfish:jakarta.json:2.0.1 does not show the original problem anymore. So the solution is to switch to the newer library.

Related

Kotlin Multiplatform library unresolved dependency at runtime

I'm making a private Kotlin Multiplatform library that will be in a private repo hosted on Bitbucket.
My library depends on another library, called Krypto.
So, naturally, I have the following dependency in the common module of the library:
val commonMain by getting {
dependencies {
api("com.soywiz.korlibs.krypto:krypto:2.2.0")
}
}
Now, when I import the library via Cocoapods to an iOS project, it works perfectly fine. However when I insert the .jar file to my Android project as a dependency:
implementation files('libs/MyLibrary-jvm-1.0.0.jar')
it compiles, but at runtime crashes with the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/soywiz/krypto/SHA256Kt
If I add the Krypto dependency to my Android project, everything works fine, however I would like the dependencies to be already included in my library. How to do that?
I also tried adding the java-library plugin and adding the dependency in a java build block, but it didn't change anything.
The solution was in the documentation all along... https://kotlinlang.org/docs/multiplatform-build-native-binaries.html#export-dependencies-to-binaries
In the Gradle configuration of the binaries of a specific platform we need to use export() to include dependencies. To also include dependencies of the dependencies, we need to do export(dep, transitiveExport = true).
kotlin {
sourceSets {
commonMain by getting {
dependencies {
api(project(":dependency"))
}
}
}
java().binaries {
framework {
export(project(":dependency"), transitiveExport = true)
}
}
}

How to tell Gradle to get sources from project instead of sources jar when adding project dependency?

I have an Android library module that depends on a Kotlin Multiplatform module via project dependency. My issue is that when I try to go to the source of a class, it takes me to the imported sources jar instead of the project that I am depending on. Is it possible to have it take me to the project's source instead of to the sources artifact? My setup:
android-local/build.gradle.kts
dependencies {
api(project(":android-remote", "jvmDefault"))
}
I don't know if this is possible with the multiplatform plugin, but thought I would ask just in case.
In order to get this working correctly first I had to add Kotlin's multiplatform plugin to my Android library module. Then I used the jvmDefault configuration in my dependencies instead of hooking up a specific Android target in my MP project. Here is the build file for my android-local now:
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.multiplatform")
}
android {
//setup
}
kotlin {
android()
sourceSets {
val androidMain by getting {
dependencies {
api(project(":android-remote", "jvmDefault"))
}
}
}
}
And now I can go to sources in the android-remote project (which is a MPP). A bit unintuitive, but it works.

local dependencies from root multi project build in gradle

I have been working on an android app built using the ResearchStack skin framework pulled in through the gradle dependency:
implementation 'org.researchstack:skin:1.1.2'.
I am interested in possibly doing some customization to the underlying ResearchStack skin framework:
https://github.com/ResearchStack/ResearchStack.
Can anyone walk me through updating my project to be dependent on local ResearchStack build artifacts so that I can make changes to the framework and see those changes in my local application.
I tried just pointing to the build output:
implementation fileTree(dir: '../../ResearchStack/skin/build/outputs/aar', include: ['*.aar'])
but that leaves me with unresolved transitive dependencies and some build issues that I couldn't quite get worked out.
Thanks!!
John,
Put 'ResearchStack skin framework code' in another directory 'myResearchStack' at root level parallel to 'app' directory.
And update the root level 'build.gradle' as
apply plugin: 'com.android.application'
android { ... }
dependencies {
// Dependency on a local library module
implementation project(":myResearchStack")
}

Firebase admin sdk dependency on gradle causing boot layer error

I'm trying to build a desktop app using javafx for extracting data from pdf and save the content as json in firebase. Adding the firebase admin sdk dependency on gradle causes build error. But it is working with maven projects.
I've created the gradle project using this guide- https://openjfx.io/openjfx-docs/#IDE-Intellij and for firebase admin sdk I've followed the official docs.But it keeps creating ResolutionException and mentions some modules.Adding dependencies or jars for those modules causes more module exceptions. I'm trying to avoid maven as it causes some conflicts with javafx which I also couldn't solve.
This is my current build.gradle file:
plugins {
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.5'
}
group 'com.tiptoptips'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.google.firebase:firebase-admin:6.7.0'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
}
mainClassName = 'com.tiptoptips.MainApp'
and here is the error I get while running or building this project-
> Task :run FAILED
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules proto.google.common.protos
and gax.grpc export package com.google.longrunning to module
javafx.graphicsEmpty
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':run'.
> Process 'command '/usr/lib/jvm/java-11-openjdk-amd64/bin/java'' finished with non-zero exit value 1
Is there anything I'm doing wrong?
After about 4 days research, I found a way to solve it. I had to download the javafx-11 libs manually and add it to the project using vm options. I had to add javafx.controls and javafx.fxml manually. Then re-adding the firebase admin sdk into the gradle worked fine. I still couldn't get why intellij was showing firebase is missing module instead of locating the javafx files. Complete details can be found here- https://openjfx.io/openjfx-docs/#install-javafx

.kts script in a Gradle project

I have a Kotlin Gradle project.
If I create a .kts file it runs in InteliJ alright except when it is in the /src/main/kotlin folder.
IDEA highlights the whole file in red.
Gradle throws out compilation exception.
The exception is
...src/main/kotlin/test.kts: (3, 1): Cannot access script base class 'kotlin.script.templates.standard.ScriptTemplateWithArgs'. Check your module classpath for missing or conflicting dependencies`.
What is the problem?
My build.gradle:
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.3.0-rc-131'
}
group 'kotlin.tutorials.coroutines'
version '1.0-SNAPSHOT'
repositories {
maven { url 'http://dl.bintray.com/kotlin/kotlin-eap' }
mavenCentral()
jcenter()
maven { url "https://dl.bintray.com/kotlin/ktor" }
}
ext.ktor_version = '1.0.0-alpha-1'
ext.coroutines_version = '0.30.2-eap13'
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
compile "io.ktor:ktor-server-netty:$ktor_version"
compile "ch.qos.logback:logback-classic:1.2.3"
//KTOR features
compile "io.ktor:ktor-jackson:$ktor_version"
compile "io.ktor:ktor-auth:$ktor_version"
compile "io.ktor:ktor-auth-jwt:$ktor_version"
compile "io.ktor:ktor-freemarker:$ktor_version"
compile "io.ktor:ktor-html-builder:$ktor_version"
}
compileKotlin.kotlinOptions.jvmTarget = "1.8"
compileTestKotlin.kotlinOptions.jvmTarget = "1.8"
.kts files should go to the src/main/resources folder since src/main/kotlin is for .kt files.
Scripts are a completely different animal in this sense, and you should use something like KtsRunner to execute them.
Related question is here.
If you just want to use scripts from IDEA, then you should use Scratch files which are supported out of the box.
The solution turned out to be very straight forward.
The compiler could not find utility classes that are usually added to any Kotlin script classpath. Adding one dependency to my build.gradle fixed it:
dependencies {
compile "org.jetbrains.kotlin:kotlin-scripting-jvm"
}
P.S.
I created 2 tickets to improve Kotlin script support in InteliJ:
https://youtrack.jetbrains.com/issue/KT-27542
https://youtrack.jetbrains.com/issue/KT-27544
If you care about those features, please vote them up!

Resources