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
Related
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.
I have downloaded a gradle spring boot project from GitHub. I'm using STS (Spring Tool Suite). I have downloaded the Gradle plugin from marketplace. and I have tried options such as manually adding the eclipse and eclipse-wtp plugins and the classpath like below to the build.gradle file:
plugins {
id 'eclipse-wtp'
id 'org.springframework.boot' version '2.4.13'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id 'jacoco'
id "org.unbroken-dome.test-sets" version "4.0.0"
}
eclipse {
classpath {
file {
whenMerged {
def source = entries.find { it.path == 'src/main/java' }
source.entryAttributes['ignore_optional_problems'] = 'true'
}
}
}
}
However, I cannot build the project and I get error messages on imports related to annotations such as below:
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Can you please guide me in how to build this gradle project with STS and resolve the errors?
p.s. I have downloaded latest gradle too. if I navigate to the project folder on CMD and run it with "gradle bootRun", tomcat comes up properly. but I don't know how to set it up on STS!
If you download and use the latest Spring Tools 4 for Eclipse distribution, there is usually nothing you need to add in order to use Gradle, the Buildship tooling comes pre-installed.
With that, you can select "Import -> Gradle / Existing Gradle Project", select your Gradle project, and go from there.
If your Gradle build file works in general, this should work just fine in the IDE, including resolving all the necessary dependencies that you have defined in your build file. So if your Gradle build runs fine from the command line, the import into the IDE should work as well.
Deploying one of my example JavaFX applications to an Android device via the gluon-mobile Eclipse plugin fails with an IllegalArgumentException in the retrolambda plugin. This is caused by an indirect dependency of my project on jaxb-api-2.3.0.jar which is a multi-release jar. Retrolambda obviously cannot handle the Java 9 parts in this file and instead of just ignoring them throws an exception. How can this be fixed or avoided?
A newer version of retrolambda (2.5.3 instead of 2.5.1) can handle the module-info.class already but not the part in the META-INF/versions/9/...
The problem could be cured by just deleting the META-INF stuff but when I do that manually it is always re-created by the gluon plugin.
Update 1:
Adding
packagingOptions {
exclude '/META-INF/versions/9/javax/xml/bind/ModuleUtil.class'
}
to the android section in the build file does not make any difference. The error message is still the same:
java.lang.IllegalArgumentException
at net.orfjackal.retrolambda.asm.ClassReader.<init>(ClassReader.java:185)
at net.orfjackal.retrolambda.asm.ClassReader.<init>(ClassReader.java:168)
at net.orfjackal.retrolambda.ClassAnalyzer.analyze(ClassAnalyzer.java:25)
at net.orfjackal.retrolambda.Retrolambda$1.visitClass(Retrolambda.java:71)
at net.orfjackal.retrolambda.files.ClasspathVisitor.visitFile(ClasspathVisitor.java:29)
at net.orfjackal.retrolambda.files.ClasspathVisitor.visitFile(ClasspathVisitor.java:11)
at java.nio.file.Files.walkFileTree(Files.java:2670)
at java.nio.file.Files.walkFileTree(Files.java:2742)
at net.orfjackal.retrolambda.Retrolambda.visitFiles(Retrolambda.java:107)
at net.orfjackal.retrolambda.Retrolambda.run(Retrolambda.java:68)
at net.orfjackal.retrolambda.Main.main(Main.java:28)
This can also be verified easily by just running the command line version of retrlambda over the extracted classes of jaxb-api-2.3.0.jar
Update 2:
With Java 9 and the Gluon-VM it fails with:
Execution failed for task ':SingleViewProject - Gluon VMApp:apkDebug'.
> Duplicate files at the same path inside the APK: META-INF/LICENSE.txt
File 1: /Users/mpaus/.m2/repository/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar
File 2: /Users/mpaus/.m2/repository/javax/xml/bind/jaxb-api/2.3.0/jaxb-api-2.3.0.jar
jaxb-api-2.3.0.jar is a multi-release jar and the current jfxmobile plugin 1.3.10 can't deal with it.
The plugin, that targets Java 7/8, uses retrolambda to port back to Java 6/7 a given dependency.
Even if you try to remove the module-info.class or the 9 versionMETA-INF.versions.9.javax.xml.bind`, these classes are processed by the retrolambda plugin, and this will lead to the exception posted in the question. Using the latest retrolambda version doesn't help either.
android {
retrolambdaVersion = "2.5.3"
manifest = 'src/android/AndroidManifest.xml'
packagingOptions {
exclude '/module-info.class'
exclude '/META-INF.versions.9.javax.xml.bind/ModuleUtil.class'
}
}
The only way to make it work under Java 8/jfxmobile 1.3.10 is by modifying the plugin, to add the following exception to JFXMobilePlugin:
copyClassesForRetrolambda.include '**/*.class'
copyClassesForRetrolambda.includeEmptyDirs = false
// exception for multi-release jars
copyClassesForRetrolambda.exclude 'META-INF/versions/**/*.class'
copyClassesForRetrolambda.exclude 'module-info.class'
and then build the plugin and use a local snapshot.
The good news is that using the jfxmobile plugin version 2.0.20 and Gluon VM, that targets Java 9+, the above is already included.
If you can switch to Java 9/10, modify your project to use this plugin, create a new project with the Gluon IDE plugin ('single view project with Gluon VM'), or follow this sample, but using the latest version (2.0.20 so far).
buildscript {
repositories {
jcenter()
google()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:2.0.20'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = '...'
sourceCompatibility = 1.8
targetCompatibility = 1.8
dependencies {
compile 'com.gluonhq:charm:5.0.0-jdk9'
androidRuntime 'com.gluonhq:charm:5.0.0'
compile 'javax.xml.bind:jaxb-api:2.3.0'
}
Is it possible to make one custom plugin in Grails 3 dependent on another custom plugin? Here's my project structure:
grails3-home
myApp
customPlugin1
build.gradle
settings.gradle
customPlugin2 ...
I would like to make customPlugin1 dependent on customPlugin2. Everything I've read says this possible with multi-project builds between apps and plugins in Grails 3. And I'm able to declare both plugins as dependencies in myApp with no issues. However, I have not been successful in getting this to work between the two plugins.
I have added the following line to customPlugin1 > settings.gradle
include "customPlugin2"
And to customPlugin1 > build.gradle
grails {
plugins {
compile project(':customPlugin2')
}
}
However when I try to build customPlugin1, I get the following error:
FAILURE: Build failed with an exception.
What went wrong:
A problem occurred configuring root project 'customPlugin1'.
Could not resolve all dependencies for configuration ':runtime'.
Project : declares a dependency from configuration 'compile' to configuration 'default' which is not declared in the descriptor for project :customPlugin2.
Is anyone aware if what I'm trying to do is possible, and if so, what I might be missing?
Update:
If I change my configuration to
include "../customPlugin2"
and
grails {
plugins {
compile project(':../customPlugin2')
}
}
the plugin builds successfully, but I am no longer able to import domains classes from customPlugin2 into customPlugin1 domains classes
You should do the include in the root settings.gradle
include 'myApp', 'customPlugin1', 'customPlugin2'
Then in plugin 1:
grails {
plugins {
compile project(':customPlugin2')
}
}
Note that this simply defines a dependency. If you need plugin 2 to load before or after plugin 1 you need to define that as well in the plugin descriptor.
I'm trying to upgrade some Gradle projects from Kotlin 1.0.6 to its latest version (1.1.0). However, whenever it reaches the compileKotlin task it fails:
:kiwi-common-kotlin:compileKotlin FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':kiwi-common-kotlin:compileKotlin'.
> Could not find Kotlin Compiler jar. Please specify compileKotlin.compilerJarFile
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
The project itself is divided in a bunch of subprojects. To avoid dupes, we have a separate file with the Kotlin definitions and import it on the projects using it:
File: gradle/kotlin.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
apply plugin: org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper
compileKotlin {
kotlinOptions.jvmTarget = "1.6"
}
And we import it in the subprojects like this:
apply from: "$rootDir/gradle/kotlin.gradle"
Since we previously tried the early preview releases and it worked seamlessly, I changed the version a couple times to see in which version the plugin broke. It turns out it works up to 1.1-M03; beginning at 1.1-M04 it shows the exact same error as in the 1.1.0 release.
We're using Gradle 2.10 in the project. Can you help me figure out whether it is a problem in our configuration? or a known issue with the Kotlin plugin itself?
It turned out to be a bug with the Gradle plugin. As pointed out by hotkeys' comment, updating to v1.1.2 fixes it.